Unlimited Web Space

Enjoy Unlimited web hosting

Aug 27, 2011

PIVOT/UNPIVOT

This changes the matrix of the table by making a column as rows and vice versa



SELECT Column1,
    Column2 AS @name,
    Column3 AS @name2
FROM
    (SELECT query that produces the data)
    AS @name
UNPIVOT/PIVOT
(
    @name2
FOR
[<column that contains the values that will become column headers>]
    IN ( Column1, COLUMN2,
  ) AS XYZ

<optional ORDER BY clause>;


No comments:

Post a Comment