col1 col2 col2
m1 1 a
m1 1 b
m1 1 c
m2 2 d
m2 2 e
m2 1 f
output
---------
m1 1,a,b,c,f
m2 2,d,e
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Khan Abrar AhmedPosted Aug 7, 2014, 1:31 AM
declare @table as table (col1 varchar(64),col2 int,col3 varchar(64))
insert into @table values ('m1',1,'a'),('m1',1,'b'),('m1',1,'c')
,('m2',2,'d'),('m2',2,'e'),('m1',1,'f')
select distinct col1,col2,(
select col3+',' from @table t1 where t1.col2=t2.col2 and t1.col1=t2.col1 for xml path(''))
from @table t2
Guest UserPosted Jul 21, 2014, 5:12 AM
You can google for examples on the same