Link to home
Start Free TrialLog in
Avatar of swaggrK
swaggrK

asked on

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 5
a_ActorIdentifierName as Actor
      ,a_AssignmentsIdName as Assignments
      ,a_partsandincrementsId as AssignmentsID
  FROM a_partsandincrements
  WHERE a_ActorID IN ('11122,'22233') 											

Open in new window


This is the output of my sample query.

Actor	                   Assignments	                  AssignmentsID
Arr, Andrew	Full Swing	                    23
Arr, Andrew	Media Fee	                    32
Arr, Andrew	Extra Risk	                                      43
Arr, Andrew	Understudy Principal	   15
Arr, Andrew	Understudy Principal	   18
Smith, Steve	Full Swing 	                     31
Smith, Steve	Dance Captain 	                     49

Open in new window


I would like for my output to look like this:

Actor	                   Full Swing     Media Fee       Extra Risk       Understudy Principal	Dance Captain 
Arr, Andrew               1                     1                       1                         2                                             0
Smith, Steve               1                    0                        0                         0                                             1

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mark Bullock
Mark Bullock
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of swaggrK
swaggrK

ASKER

I made a mistake in my sample output. The AssignmentIDs are unique.

Actor	                   Assignments	                  AssignmentsID
Arr, Andrew	Full Swing	                    1
Arr, Andrew	Media Fee	                    4
Arr, Andrew	Extra Risk	                                      8
Arr, Andrew	Understudy Principal	   15
Arr, Andrew	Understudy Principal	   15
Smith, Steve	Full Swing 	                     1
Smith, Steve	Dance Captain 	                     3
Smith, Steve	Media Fee	                     4

Open in new window

Avatar of swaggrK

ASKER

@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?