Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help on Query

Author  Topic 

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2011-03-23 : 02:40:57

table2
ID Name
001 ABC
002 XYZ

table1
ID
001
002
003
..........

In that case, how to get comma seperated name of table2 ?
Based on some condition, I will get some ID of table1 and want to retreive comma seperated name from table2 .

Thanks.

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2011-03-23 : 04:17:08
Can I use IN operator ?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-03-23 : 04:26:01
not really sure what do you need. Probably this ?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kwikwisi
Constraint Violating Yak Guru

283 Posts

Posted - 2011-03-23 : 04:42:54
This returns 2rows (2 product numbers) and I wanted to make
them as one comma seperated value . (Eg. product001,product002)

SELECT productnumber
FROM Productbase
WHERE productid IN (
select productid from invoicedetailbase
where invoiceid = 'abcd' and productid is not null
)




quote:
Originally posted by khtan

not really sure what do you need. Probably this ?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254


KH
[spoiler]Time is always against us[/spoiler]



Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-03-23 : 04:46:17
quote:
Originally posted by kwikwisi

This returns 2rows (2 product numbers) and I wanted to make
them as one comma seperated value . (Eg. product001,product002)

SELECT productnumber
FROM Productbase
WHERE productid IN (
select productid from invoicedetailbase
where invoiceid = 'abcd' and productid is not null
)




quote:
Originally posted by khtan

not really sure what do you need. Probably this ?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254


KH
[spoiler]Time is always against us[/spoiler]







Refer to the link. Use the for xml path method there


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -