| Author |
Topic  |
|
|
jimoomba
Yak Posting Veteran
India
86 Posts |
Posted - 11/23/2012 : 05:16:40
|
Hello,
I have a delima, and im not really sure if this possible. But i have a table like lets say
id | data1 1 this 2 that 3 stuff
i want to be able to return this as one row with the data from data1 in one column inside colons each seperated by commas.
so the result would be
1 Column 'this', 'that', 'stuff'
can anyone help me with this.
Thank you,
rams |
|
|
bandi
Flowing Fount of Yak Knowledge
India
1451 Posts |
Posted - 11/23/2012 : 06:43:58
|
DECLARE @tab1 TABLE(id int, data1 varchar(10)) INSERT INTO @tab1 VALUES(1, 'this'),(2, 'that'),(3, 'stuff')
--Solution1: DECLARE @a varchar(1000) SELECT @a = COALESCE(@a + ', ', '') + data1 FROM @tab1 SELECT @a
--Alternate is:
SELECT id, STUFF((SELECT ',' + data1 FROM @tab1 FOR XML PATH('')),1,1,'') AS CSV FROM @tab1
-- Chandu |
Edited by - bandi on 11/23/2012 06:53:12 |
 |
|
| |
Topic  |
|
|
|