Creating Pivot Tables

The last thing we'll do today is look at a method for generating a pivot table using aggregates and grouping. Pivot tables, also called cross-tabs, are different from regular result sets because the column headings are drawn from the data itself. One column in the data is selected to become the headings for the cross-tab report. To understand this better, you need to see the result set for a pivot table. Then we will step through the process of building it. The result set we will produce analyzes current (1998) and prior (1997) year orders for the first five months of the year:

 Month Orders 1998 Orders 1997 Percent Change --------- ----------- ----------- ------------------------- January 55 33 66.666666 February 54 29 86.206896 ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.