I am not sure that this is possible, but here is what I'm trying to do. For any given group of customers, I have current balance, number of customer accounts, amounts 30 days past due, amounts 60 days past due, and amounts 90 days past due. I can write the following: SELECT * FROM ( SELECT DATE ,ACCTNO ,CUSTOMER ,BALANCE ,30D_BALANCE ,60_D_BALANCE ,90_D_BALANCE FROM PRODUCTION ) a PIVOT( SUM(BALANCE) FOR DATE IN (TODAY)) AS Piv1 Can I add additional pivots?
You can, by joining, but it might get a bit messy and also quite inefficient: select * from pvt1 join ( ) pvt2 on pvt1.Key = pvt2.Key etc... It might be better if you used a case statement, which I seem to recall is a bit more efficient anyway. (In fact, here's the Jeff Moden article that proves it