Concatentate using group by

0

Please login or register to vote for this query.

(click on this box to dismiss)

Moderators

Q&A for community managers, administrators, and moderators

-- Change the value of UserId below
-- to avoid fetching a cached result set

DECLARE @UserId int = ##UserId##

select C1.object_id,
       stuff((select ','+C2.name
              from sys.all_columns as C2
              where C1.object_id = C2.object_id
              for xml path(''),  type).value('.', 'nvarchar(max)'), 1, 1, '')
from sys.all_columns as C1
group by C1.object_id

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results