create table #temp
(CustomerID int ,[date] datetime ,
SubTotal varchar(20))
select * from #temp
--insert into #temp values(4,getdate(),34)
SELECT * FROM
(SELECT CustomerID, DATEPART(m, date) OrderMonth, SubTotal
FROM #temp
WHERE date between '20030101' and '20101231'
and CustomerID IN (2,4,6,7,8,9)) src
PIVOT (SUM(SubTotal) FOR OrderMonth
IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) AS pvt
GO
No comments:
Post a Comment