I have two tables:
and
and I need to get to this (there is other SQL that I will tie these results to):
I can't seem to get the PIVOT syntax correct- it has to be dynamic as I don't know all the ItemNames (and there could be hundreds).
Anyone help out?
Thanks in advance.
Code:
CheckListItems
CheckListItemId ItemName
1 name1
2 name2
3 name3
4 name4
5 name5
...
and
Code:
CheckListItemResponses
CheckListResponse CheckListItemId
Yes 1
No 1
Seattle 3
Boat 4
Plane 4
and I need to get to this (there is other SQL that I will tie these results to):
Code:
Name1 Name2 Name3 Name4 Name5 ...
Yes
No Seattle Boat
Plane
I can't seem to get the PIVOT syntax correct- it has to be dynamic as I don't know all the ItemNames (and there could be hundreds).
Anyone help out?
Thanks in advance.