SQL Server Pivot Row Total -


i'm using sql server 2012 , have below pivot code works fine. however, how include row total i.e. sum of recorded amount each account on course of year?

select * ( select [account],[accountdesc], convert(char(4), accdate, 100) [month], [recordedamount] [tblgls215_2016_2017] [employee] = @employee ) s pivot ( sum ([recordedamount]) [month] in (jan, feb, mar, apr, may, jun, jul, aug, sept, oct, nov, dec) ) pvt 

any appreciated.

if interested final working solution:

select pvt.* ,isnull(pvt.jan,0) +isnull(pvt.feb,0) +isnull(pvt.mar,0) +isnull(pvt.apr,0) +isnull(pvt.may,0) +isnull(pvt.jun,0) +isnull(pvt.jul,0) +isnull(pvt.aug,0) +isnull(pvt.sept,0) +isnull(pvt.oct,0) +isnull(pvt.nov,0) yeartotal ( select [account],[accountdesc], convert(char(4), accdate, 100) [month], [recordedamount] [tblgls215_2016_2017] [employee] = @employee ) s pivot ( sum ([recordedamount]) [month] in (may, jun, jul, aug, sept, oct, nov, dec, jan, feb, mar, apr) ) pvt 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -