In this article we'll show you how to use SQL Server PIVOT operator. The PIVOT operator is useful when you want to generate cross-tabular views to summarize data.

What is PIVOT?

PIVOT rotates a table-valued expression by turning the unique values from one column in the expression into multiple columns in the output, and performs aggregations where they are required on any remaining column values that are wanted in the final output. UNPIVOT performs the opposite operation to PIVOT by rotating columns of a table-valued expression into column values.

Scripting the Code

We'll begin first with defining a common row-level query to capture total sales by year and quarter.

About Us

InfoToad Consulting provides Data Management, Business Intelligence and Advanced Analytics solutions. If you would like to learn more about our services or solutons, please visit us at http://www.infotoad.com or call us at (877) 488-0566.