April 2006
Intermediate to advanced
640 pages
16h 46m
English
Unpivoting is the opposite of pivoting—namely, rotating columns to rows. Unpivoting is usually used to normalize data, but it has other applications as well.
Unpivoting is not an exact inverse of pivoting, as it won’t necessarily allow you to regenerate source rows that were pivoted. However, for the sake of simplicity, think of it as the opposite of pivoting.
In my examples, I’ll use the PvtCustOrders table, which you create and populate by running the code in Example 6-6.
Example 6-6. Creating and populating the PvtCustOrders table
USE tempdb; GO IF OBJECT_ID('dbo.PvtCustOrders') IS NOT NULL DROP TABLE dbo.PvtCustOrders; GO SELECT * ...Read now
Unlock full access