try using this as a model - not sure if this is what you're looking for but it should help:;with butt as( select FDMSAccountNo = 878714963880, Fee_Sequence_Number = '18j', Retail_amount = 10, month_end_date = '2013-01-01' union all select FDMSAccountNo = 878714963880, Fee_Sequence_Number = '18j', Retail_amount = 11, month_end_date = '2013-02-01' union all select FDMSAccountNo = 878714963880, Fee_Sequence_Number = '18j', Retail_amount = 12, month_end_date = '2013-03-01')select FDMSAccountNo, [2013-01-01], [2013-02-01], [2013-03-01], Fee_sequence_numberFROM ( SELECT FDMSAccountNo, Fee_Sequence_Number, Month_end_date, sum([Retail_amount])as Auth_Sales FROM butt where FDMSAccountNo = 878714963880 and Month_end_date between '2013-01-01' and '2013-10-01' group by FDMSAccountNo,Fee_Sequence_Number, Month_end_date ) as pPIVOT (MAX([Auth_Sales]) FOR Month_end_date in ( [2013-01-01],[2013-02-01],[2013-03-01])) as pvtOUTPUT:FDMSAccountNo 2013-01-01 2013-02-01 2013-03-01 Fee_sequence_number--------------------------------------- ----------- ----------- ----------- -------------------878714963880 10 11 12 18j
Be One with the OptimizerTG