Changing SQL Query Output from Columns to Row Headers
I have a table that contains actor assignments that I need to display as column headers and count how many of those assignments an actor has participated in,
This is my sample query:
SELECT TOP 5a_ActorIdentifierName as Actor ,a_AssignmentsIdName as Assignments ,a_partsandincrementsId as AssignmentsID FROM a_partsandincrements WHERE a_ActorID IN ('11122,'22233')
Actor Assignments AssignmentsIDArr, Andrew Full Swing 23Arr, Andrew Media Fee 32Arr, Andrew Extra Risk 43Arr, Andrew Understudy Principal 15Arr, Andrew Understudy Principal 18Smith, Steve Full Swing 31Smith, Steve Dance Captain 49
I made a mistake in my sample output. The AssignmentIDs are unique.
Actor Assignments AssignmentsIDArr, Andrew Full Swing 1Arr, Andrew Media Fee 4Arr, Andrew Extra Risk 8Arr, Andrew Understudy Principal 15Arr, Andrew Understudy Principal 15Smith, Steve Full Swing 1Smith, Steve Dance Captain 3Smith, Steve Media Fee 4
@Mark Bullock
Your suggestion works but it outputs a row for every actor and when I add DISTINCT, it only outputs one actor.
How can I get the query to output a single row for every actor?
Open in new window