Q&A for scientists using computers to solve scientific problems
create table #t(pageno int, groupid varchar(10)) insert #t values (100100, 'mpadilla') insert #t values (100101, 'Mine') declare @a varchar(4000) select @a = coalesce(@a + x, x) from (select top 100 percent '[' +groupid + ']=MAX(CASE groupid WHEN ''' +groupid+ ''' THEN ''X'' ELSE ''--'' END)' x from #t DistinctPages Group by groupid order by groupid) t select @a