Code
if not object_id('Tab2') is null
drop table Tab2
Go
Create table Tab2(id int,[COl2] nvarchar(10))
Insert Tab2
select 1,N'c' union all
select 1,N'b' union all
select 1,N'a' union all
select 2,N'd' union all
select 2,N'e' union all
select 3,N'f'
declare @quote varchar(10)
select @quote=','
select id,stuff((select @quote+[col2] from dbo.Tab2 where id=x.id order by col2 for xml path('')),1,len(@quote),'')
from dbo.Tab2 x group by id
|