@zerodoc: If you need to dynamically generate the columns you will nee to write some dynamic SQL. Not rocket science, but a bit tedious. (Or, read the unpivoted query results in a tool such as Access or Excel which already knows how to dynamically size a Pivot table.)