December 13, 2011 at 7:57 am
hello, can anyone please show me how to concatenate values from multiple rows to single row ??
for e.g
create table test_table
(
letter varchar(max),
word varchar(max)
);
insert into test_table
values
('A','apple'),
('A','aeroplane'),
('C','car'),
('D','dairy'),
('C','camel');
the output should be as follows
letter words
----- ---------------
A apple,aeroplane
C car,camel
D dairy
I would greatly appreciate your help.
December 13, 2011 at 7:59 am
Dyn-o-mite!! (12/13/2011)
hello, can anyone please show me how to concatenate values from multiple rows to single row ??for e.g
create table test_table
(
letter varchar(max),
word varchar(max)
);
insert into test_table
values
('A','apple'),
('A','aeroplane'),
('C','car'),
('D','dairy'),
('C','camel');
the output should be as follows
letter words
----- ---------------
A apple,aeroplane
C car,camel
D dairy
I would greatly appreciate your help.
SELECT letter, STUFF((SELECT ',' + word
FROM test_table t2
WHERE t2.letter = t1.letter
ORDER BY word
FOR XML PATH('')), 1, 1, '') AS words
FROM test_table t1
GROUP BY letter
December 13, 2011 at 8:06 am
thank you very much !!!
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply