Example
Team | Person1 | Person2 | Person3
change to
Team | Person 1
Team | Person 2
Team | Person 3
I wasn't sure how to describe exactly what it was that I wanted to do, sorry if this is a duplicate.
Example
Team | Person1 | Person2 | Person3
change to
Team | Person 1
Team | Person 2
Team | Person 3
I wasn't sure how to describe exactly what it was that I wanted to do, sorry if this is a duplicate.
Use UNPIVOT
For table dbo.Teams, using your example:
SELECT Team, Person
FROM
(
SELECT Team, Person1, Person2, Person3
FROM dbo.Teams
) as cp
UNPIVOT
(
Person FOR Persons IN (Person1, Person2, Person3)
) AS up;
While using UNIONs
works, it does not scale well, costing a lot more for each additional column you need to transpose.
NOTE: This is basically a clone of the solution to a near identical question at this article, provided in the initial question comments by user @Goat CO. See the link for additional information and expansion on this solution.
I think you might try (besides the the solution user @GoatCO mentioned in the comments) the following query:
SELECT Team, [Person 1] As Person_Column
FROM _table
UNION ALL
SELECT Team, [Person 2] As Person_Column
FROM _table
UNION ALL
SELECT Team, [Person 3] As Person_Column
FROM _table