Post navigation

Simple SQL Pivot with Example

A colleague was interested in solving a reporting problem for our business users. And as many times go, I ask him what he wants the end result to be, so that I can figure out how I would tackle the problem. He explains that he wants the following:

License #

#1

#2

#3

0001

2000

500

0002

500

0003

200

100

…

…

…

…

This table represents a Personal Identifier (Drivers License ID, Business ID, etc), followed by fine amounts (the lower number being the most recent fine). Other examples will use column headers of other known values such as product lines (Apples, Oranges, etc), or dates (Jan 2011, Feb 2011, etc) as summation values.

RJ writes custom Windows and Web applications using the Microsoft .NET framework, and enjoys solving problems with code, often while listening to a techno soundcloud stream. He hopes to one day write an application that many businesses will use.