I have a table
Title Name Type
------------------------------------------------
T1 A Primary
T1 B Primary
T2 B Primary
T2 C Secondary
T2 D Secondary
I need the output to be
Title Primary Secondary
------------------------------------------------
T1 A, B NULL/Blank
T2 B C, D
[Name] column in the original table can have any value. i.e. later there could be E, F, G etc.
How can this be done?
Then you need dynamic SQL. Consider something like this for generating the list of columns:
Now you can use @collist to help construct the query you want, which you then run using
sp_executesqlLike this: