I need to be able to dynamically generate the date columns for my PIVOT result table.My Sales Table contains data as follows:partNo |period |Qty12343758|2010-12 |143211020|2010-07 |232141437|2010-05 |312431414|2010-08 |212343758|2010-11 |143211020|2010-06 |232141437|2010-09 |312431414|2010-06 |243211020|2010-06 |2The PIVOT query I've written looks like this:SELECT part_number, [2010-01], [2010-02], [2010-03], [2010-04], [2010-05], [2010-06], [2010-07], [2010-08], [2010-09], [2010-10], [2010-11], [2010-12]FROM (SELECT part_number,period,QtyFROM test) p PIVOT (SUM(Qty) FOR period in ( [2010-01], [2010-02], [2010-03], [2010-04], [2010-05], [2010-06], [2010-07], [2010-08], [2010-09], [2010-10], [2010-11], [2010-12]]) ) as pvt
This works fine, except I need to be able to generate the column headings dynamically depending on which month it is because I always only want to look back on 6 months past the current month. Any help would be greatly appreciated.