create table #workingtable ( ControlDetailID int not null, LookupValue nvarchar(50) not null, List nvarchar(4000) null )insert into #workingtable (ControlDetailID, LookupValue)select ControlDetailID, LookupValuefrom Patricks_Tableorder by ControlDetailID, LookupValuedeclare @list nvarchar(4000), @lastID intselect @list = '', @lastID = ''update #workingtableset @list = list = case when @lastid <> ControlDetailID then LookupValue else @list + ', ' + LookupValue end, @lastid = ControlDetailIDselect ControlDetailID, max(List) as CSVfrom #workingtablegroup by ControlDetailID
Jay White{0}