SELECT STUFF((select ',' + quotename (C.name) from sys.columns c where c.object_id = OBJECT_ID('dbo.result2') for xml path(''), TYPE).value('(./text())[1]', 'NVARCHAR(MAX)'),1,1,'');