Using PIVOT to simplify a cross tab style queries

The Pivot function is introduced in MS SQL Server 2005. If you are still using SQL Server 2000 or lower (unlikely), you may skip this section. Pivot table is a common term. I have used it in Excel extensively. If you are not familiar with it, run a sample query here.

Even if your SQL server version is equal or higher than 2005, you may still get an error message because the compatibility level of the server has to be 2005 or higher. You can change this level under SQL Server Management Studio if the compatibility level is low.

Pivot function is a very useful tool to simplify long repeating queries.

Case 9-P1—Monthly sales by geography

A user would like to get a listing of each state's sales by month. ...

Get Mastering SQL Queries for SAP Business One 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.