Here ya go:create table #workingtable ( i int not null, vc varchar(50) not null, list varchar(8000), constraint pk_wt primary key (i,vc) )insert into #workingtable (i,vc)SELECT c.Class_ID AS Class_ID, ci.Instructor_Name AS Instructor_NameFROM CLASS cINNER JOIN Class_Instructor ci ON c.Class_ID = ci.Class_IDORDER BY c.Class_IDdeclare @list varchar(8000), @lasti intselect @list = '', @lasti = -1--here is the meat of the workupdate #workingtableset @list = list = case when @lasti <> i then vc else @list + ', ' + vc end, @lasti = i--return a sample from the final rowsetselect top 10 i, case when len(max(list)) > 50 then convert(varchar(50), left(max(list),47) + '...') else convert(varchar(50),max(list)) end as Instructor_Namefrom #workingtablegroup by iorder by newid()goDROP TABLE #workingtable
Here is the link to the article that this solution is based on:[url]http://www.sqlteam.com/item.asp?ItemID=11021[/url]Tara