Convertion of columns into rows is widely used in real tasks. In this article we will talk about different implementations of T-SQL UNPIVOT transformations.
Let’s assume we have an aggregated table which contains data about results of the games played by each player. We have a task to convert columns into rows.
IF OBJECT_ID ('dbo.Players') IS NOT NULL DROP TABLE dbo.Players; CREATE TABLE dbo.Players ( PlayerID INT , Win INT , Defeat INT , StandOff INT , CONSTRAINT PK_Players PRIMARY KEY CLUSTERED (PlayerID) ON [PRIMARY] ); INSERT INTO dbo.Players (PlayerID, Win, Defeat, StandOff) VALUES (1, 7, 6, 9), (2, 12, 5, 0), (3, 3, 11, 1);