I some how liked the peso's way of doing it. Declare @Table Table ( ttm varchar(10), tname varchar(20), tter int )Insert @Table Select 'jj','john', 1 Union all Select 'jj','john', 2 Union All Select 'jj', 'john', 3 Union All Select 'dd','david', 1 Union AllSelect 'dd','david', 17SELECT DISTINCT ttm,tname, STUFF((SELECT ',' + cast(t2.tter as varchar(20)) FROM @Table AS t2 WHERE t2.ttm = t1.ttm and t2.tname = t1.tname FOR XML PATH('')), 1, 1, '') AS CODESFROM @Table AS t1ORDER By 3 desc
Referenced : http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=53293&whichpage=2Chiraghttp://www.chirikworld.com