February 4, 2015 at 6:14 am
I have a table T1 with only one column.
ID
1
2
3
I want to put all the records (separated by comma) in a single column of another table T2.
ID
1,2,3
Is it possible to do this without using the cursors?
Thank you.
February 4, 2015 at 6:27 am
You might be able to use this technique:
declare @T1 table (Id int)
insert @T1
(Id)
values (1),(2),(3);
with vals(x) as (select ',' + cast(Id as varchar(5)) from @T1 t
for xml path(''))
select stuff(x,1,1,'') from vals
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
February 4, 2015 at 8:22 am
For an explanation on what Phil posted.
http://www.sqlservercentral.com/articles/comma+separated+list/71700/
February 16, 2015 at 7:24 am
thank you very much
February 18, 2015 at 2:59 am
Thank you Phil, very useful!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply