SQL SERVER – Example of PIVOT UNPIVOT Cross Tab Query in Different SQL Server Versions

Transforming rows to columns (PIVOT/CROSS TAB) and columns to rows (UNPIVOT) may be one of the common requirements that all of us must have seen several times in our programming life. SQL Server 2005 introduced two new operators: PIVOT and UNPIVOT that made writing cross-tab queries easier.

My friend and SQL Server MVP Jacob Sebastian has posted an example that transform rows to columns using PIVOT operator. The reverse operation of PIVOT is UNPIVOT. PIVOT operator is available only in SQL Server 2005/2008. It does not exists in SQL Server 2000. Developers who are still using SQL Server 2000 should upgrade to SQL Server 2005 or SQL Server 2008 (recommended).

While discussion this issue with Jacob another day he wrote following posts so fast it was very impressive.

TSQL Lab 15 – Another PIVOT Query Example
TSQL Lab 16 – Generating CROSS TAB results in SQL Server 2000
TSQL Lab 17 – An example using UNPIVOT (Transforming Columns to Rows)

Articles written by me previously.

SQL SERVER – PIVOT and UNPIVOT Table Examples
SQL SERVER – PIVOT Table Example
SQL SERVER – UNPIVOT Table Example

Reference : Pinal Dave (https://blog.sqlauthority.com)

MVP, PIVOT, UNPIVOT
Previous Post
SQLAuthority News – Security Update for SQL Server 2005 Service Pack 2
Next Post
SQL Server – 2008 – Cheat Sheet – One Page PDF Download

Related Posts

Leave a Reply