I have a scenario where I need to convert rows to columns. I likely need to use PIVOT, but I haven’t been able to figure this one out.
Here is a simplified version of what I have:
Table: ContentAuthor
ContentID | AuthorName
----------------------
1 | Joe
1 | John
1 | Mary
2 | John
2 | Dan
3 | Sam
What I would like to get:
ContentID | Author1 | Author2 | Author3 | Author4 | Author5
-----------------------------------------------------------------
1 | Joe | John | Mary | |
2 | John | Dan | | |
3 | Sam | | | |
At this point I’m not really concerned with the order they show up.
Any help would be greatly appreciated.
This will work for up to 5 authors per
ContentIdif you need to allow for arbitrary amounts then you will need to use dynamic SQL