How to get Monthly Data in Sql Server

Category > MSSQLSERVER || Published on : Friday, June 12, 2015 || Views: 6199 || How to get Monthly Data in Sql Server


SELECT *
FROM (
    SELECT 
        year(Addeddate) as [year],left(datename(month,Addeddate),3)as [month], 
        AmountPaid as Amount 
    FROM Invoice
) as s
PIVOT
(
    SUM(Amount)
    FOR [month] IN (jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, [dec])
) AS PVTTable