SQL Pivot

SELECT Item, imitdesc, 'Price' as Val,[2018-1],[2018-2],[2018-3],[2018-4],[2018-5],[2018-6],[2018-7],[2018-8],[2018-9],[2018-10],[2018-11],[2018-12],[2019-1],[2019-2],[2019-3],[2019-4],[2019-5],[2019-6],[2019-7],[2019-8],[2019-9],[2019-10],[2019-11],[2019-12]
FROM (
    SELECT 
        Item,
  imitdesc,
  isnull(UPrice,0) as UPrice,
  cast(MYear as varchar) + '-' + cast(Mmonth as varchar) as Mmonth--, 
        --isnull(GRNQty,0)-isnull(IssueQty,0) as Amount 
    FROM #TempCons        
) as s
PIVOT
(
    SUM(UPrice)
    FOR [Mmonth] IN ([2018-1],[2018-2],[2018-3],[2018-4],[2018-5],[2018-6],[2018-7],[2018-8],[2018-9],[2018-10],[2018-11],[2018-12],[2019-1],[2019-2],[2019-3],[2019-4],[2019-5],[2019-6],[2019-7],[2019-8],[2019-9],[2019-10],[2019-11],[2019-12])
)AS pvt

Comments

Popular posts from this blog

Apply CSS styles to SharePoint Web parts

SharePoint Number Column Without Commas

Use of Information Rights Management (IRM) in SharePoint