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
 General SQL Server Forums
 New to SQL Server Programming
 putting records together

Author  Topic 

Y2K

2 Posts

Posted - 2009-02-09 : 06:27:28
hi,
i need help on putting the records that are returned for 1 common value.
For example: A and B are the two tables
Table A holds the continents name (Asia,America etc)
and B has all the countries stored in it.
I want all the countries coming under Asia to be in one row like,
Asia: India, China,Sri lanka etc
Right now, i am getting the result as:
Asia India
Asia China

So, I want the all the entries to be put into one row with comma seperated that come under a single ontinent.

Thanks.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-02-09 : 06:31:18
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-02-09 : 07:13:41
select distinct continent,stuff((select distinct ',' + country from tableB where continentid = a.continentid for xml path('') ),1,1,'') as 'countries'
from tableA a

Jai Krishna
Go to Top of Page
   

- Advertisement -