dandenson (4/7/2011)
desired output
name, snums
'bill','1,2'
'tom','3,20'
'john','6'
Hi,
This is what you are looking for
go
declare @Temp table(name varchar(50),Snum varchar(50) )
insert @Temp values
('bill' , 1),
('bill' , 2),
('tom' , 3),
('tom' ,20),
('john' , 6)
SELECT DISTINCT name,SUBSTRING((SELECT ','+Snum AS [text()] FROM @Temp WHERE name = T.name ORDER BY Snum FOR XML PATH( '' ) ), 2,200) AS J
FROM @Temp AS T;