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.
Articles written by me previously.
Reference : Pinal Dave (http://blog.SQLAuthority.com)