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.
I have posted an example that transforms rows to columns using the PIVOT operator here: http://blog.sqlserver.me/2008/09/pivot-cross-tab-sql-server-2005.html
PIVOT operator is available only in SQL Server 2005/2008. It does not exists in SQL Server 2000. I have posted another version of the above sample code that works in SQL Server 2000. You can find the post here: http://blog.sqlserver.me/2008/09/pivot-cross-tab-sql-server-2000.html
I have posted one more example, that performs the reverse operation (columns to rows) using UNPIVOT. You can find it here: http://blog.sqlserver.me/2008/09/unpivot-sql-server-2005.html
0 comments:
Post a Comment