You probably have it right. The code above will create 1 row for each QTR. PIVOT will create 1 row with a column for each QTR.declare @t table (QTR int, tot int)insert @tselect 5,10 union allselect 6,10 union allselect 7,10 union allselect 5,10 union allselect 6,10 union allselect 7,10select QTR, count(*) [count]from @twhere QTR in (5,6,7)group by QTRselect p.[5] as qtr5 ,p.[6] as qtr6 ,p.[7] as qtr7from @tPIVOT (count(tot) for QTR in ([5],[6],[7])) p OUTPUT:QTR count----------- -----------5 26 27 2qtr5 qtr6 qtr7----------- ----------- -----------2 2 2
Be One with the OptimizerTG