An SQL Pivot Procedure
April 21, 2015 Paul Tuohy
The basic concept of a pivot is that row values are transformed into column values. I have often wished that DB2 had a pivot procedure. But until that day arrives I will have to make do with a workaround that you might find useful too.
The workaround is in the form of a stored procedure that can be used to pivot any column in any table. Before getting to the stored procedure, let’s look at a simple pivot example.
These examples are using the SALES table in the DB2 sample database. To create the DB2 sample database on your system,