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
 Comma Separation + Sql Server

Author  Topic 

aoriju
Posting Yak Master

156 Posts

Posted - 2009-03-09 : 07:11:48
Hello,

I have a Table Table Variable Holding The Values
Test
Test1
Test2 like that on each Column

i want to retrieve that values into
Test,Test1,Test2 Like that (WithOut Using Any Loops)

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-09 : 07:13:17
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254 for SQL Server 2005 solution.



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

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-03-09 : 07:51:49
declare @temp table ( id int,val varchar(32))
insert into @temp
select 1 ,'test1' union all
select 1,'test2' union all
select 1,'test3' union all
select 2 ,'test4' union all
select 2,'test5'

select distinct id,stuff(( select ','+ val from @temp where t.id = id for xml path('')),1,1,'') as val from @temp t
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-09 : 10:43:36
Which is the solution provided in the link above.



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

- Advertisement -