PIVOT is a new T-SQL operator introduced in SQL Server 2008 which can be used to rotate rows into columns and can create a crosstab query. You can specify the PIVOT operator in FROM clause of your query.
Specify the desired values that you want to see in SELECT statement and FROM clause contains the PIVOT statement. Let us take an example
The following query uses ADVENTUREWORKS database which uses the order years as columns.
The FROM clause create the values that you want to see in rows of the newly created columns. We used the FOR operator to list the values that we want to pivot in the OrderYear Column.
The Result for the above query will look like the following
UNPIVOT operator can be used to normalize the data that is already pivoted. Let us take the example. Create a Vendor Employee table and insert some values in it.
Select the values from above created table will look like this
The Results are look like the following