create table #temp (data varchar(32))declare @sql varchar(512)insert #temp select 'a'union allselect 'b'union allselect 'c'union allselect 'd'union allselect 'e'union allselect 'e'union allselect 'f'select @sql = ''select @sql = @sql + data from #tempselect @sqldrop table #temp
SELECT STUFF(( SELECT ''+A.data FROM (SELECT DISTINCT TOP 100 PERCENT data FROM #temp ORDER BY data) AFOR XML PATH ('')),1,1,'')
SELECT TOP 1 ( SELECT DISTINCT data + '' FROM #temp FOR XML PATH(''))FROM #temp