October 21, 2015 at 2:00 am
I have a select query on table unify, here i want to display the "Desc" value from JKS table instead of "u.code" field
SELECT
u.id,
(
+ISNULL(u.desc,'')+' '
+ISNULL(u.code,'')+' '
)
from Unify u
another table 'JKS'
code | Desc
-------------
001 | LCC
002 | HHT
003 | ICH
004 | Unify
October 21, 2015 at 2:12 am
Minnu (10/21/2015)
I have a select query on table unify, here i want to display the "Desc" value from JKS table instead of "u.code" fieldSELECT
u.id,
(
+ISNULL(u.desc,'')+' '
+ISNULL(u.code,'')+' '
)
from Unify u
another table 'JKS'
code | Desc
-------------
001 | LCC
002 | HHT
003 | ICH
004 | Unify
What problem are you having?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
October 21, 2015 at 2:14 am
Minnu (10/21/2015)
I have a select query on table unify, here i want to display the "Desc" value from JKS table instead of "u.code" fieldSELECT
u.id,
(
+ISNULL(u.desc,'')+' '
+ISNULL(u.code,'')+' '
)
from Unify u
another table 'JKS'
code | Desc
-------------
001 | LCC
002 | HHT
003 | ICH
004 | Unify
Your question doesn't make a lot of sense and there are errors in the query you've posted. I think you need to join the table 'Unify' to 'JKS' in order to get the Desc value from it. With what you've posted that really is a guess and I can't do much more without some help from you. If you read the article in my signature about posting questions that will point you in the right direction.
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
October 21, 2015 at 2:34 am
Yes wants to join the two tables, in first table am trying to get the values as a single string, and i want to get the code from second table and join to the string in first table.
October 21, 2015 at 2:37 am
Table : Unify
id desc code
1 HSBOM 002
table 'JKS'
code | Desc
-------------
001 | LCC
002 | HHT
003 | ICH
004 | Unify
i want result like below
1 HSBOM HHT
October 21, 2015 at 2:41 am
Minnu (10/21/2015)
Table : Unifyid desc code
1 HSBOM 002
table 'JKS'
code | Desc
-------------
001 | LCC
002 | HHT
003 | ICH
004 | Unify
i want result like below
1 HSBOM HHT
Are you saying that you don't know how to join the tables?
Some consumable DDL, data would really help.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
October 21, 2015 at 3:05 am
Dont know how to join while concatenating the two strings.
Please help
October 21, 2015 at 3:13 am
We're trying to help but we've got no idea what your tables look like. Please do as we've asked and provide some usable data.
This link, http://www.sqlservercentral.com/articles/Best+Practices/61537/ will show you how to generate sample data to post.
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
October 21, 2015 at 3:54 am
Are you actually saying you have visited this site 844 times and
you don't know how to JOIN two tables and concatenate a couple of fields?
October 21, 2015 at 4:24 am
i Know Joins, but wants to know the syntax to replace below query with value in another table..
+ISNULL(u.code,'')+' '
October 21, 2015 at 4:31 am
Minnu (10/21/2015)
i Know Joins, but wants to know the syntax to replace below query with value in another table..+ISNULL(u.code,'')+' '
+ISNULL(x.code,'')+' '
Where x is the alias of the joined table.
I'm 99% sure that this is not what you want. But it does demonstrate that you should provide sample data, DDL etc as already requested, because you do not appear able to write out your request in a way which anyone else can comprehend.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
October 21, 2015 at 4:32 am
You're still not making a great deal of sense.
One thing is that the first '+' sign before the ISNULL will cause an error if there's nothing before it.
How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537
October 21, 2015 at 4:46 am
CREATE TABLE #Unify
(
ID INT IDENTITY(1,1),
Code CHAR(3),
DESCR VARCHAR(10)
)
CREATE TABLE #JKS
(
ID INT IDENTITY(1,1),
Code CHAR(3),
DESCR VARCHAR(10)
)
INSERT INTO #Unify
SELECT '002','HSBOM'
INSERT INTO #JKS
SELECT '001','LCC'
UNION ALL
SELECT '002','HHT'
UNION ALL
SELECT '003','ICH'
UNION ALL
SELECT '004','Unify'
SELECT u.ID, ISNULL(u.DESCR,'') + ' ' + ISNULL(j.DESCR,'') as [Description]
FROM #Unify u
INNER JOIN #JKS j
ON u.Code =j.Code
DROP TABLE #Unify
DROP TABLE #JKS
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply