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
 Row wise data Concatenation

Author  Topic 

khalik
Constraint Violating Yak Guru

443 Posts

Posted - 2009-01-13 : 03:28:57
Hi

I have a table which has person wise color. table structure

declare @test table ( Person varchar(100), color varchar(100))
insert into @test
select 'Tom','Green' union all
select 'Tom','Yelloq' union all
select 'Tom','Blue' union all
select 'Samy','Blue' union all
select 'Samy','Black' union all
select 'K','White'

i expected output shd be

Tom Green,Yellow,Blue
Samy Blue,Black
K white

can be done using simple qry

thanks

======================================
Ask to your self before u ask someone

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-13 : 03:39:51
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

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-13 : 03:53:22
select distinct Person , stuff((select ','+ color from @test where Person = e.Person for xml path('')),1,1,'') from @test e
order by person desc
Go to Top of Page

khalik
Constraint Violating Yak Guru

443 Posts

Posted - 2009-01-13 : 04:05:08
Thanks BKlr and Peso

======================================
Ask to your self before u ask someone
Go to Top of Page
   

- Advertisement -