elsenorjose
Technical User
Using SQL Server 2014, suppose I have a pivot query like so:
SELECT *
FROM (
SELECT
gl.reknr as [GL Account], oms25_0 as [Description], left(datename(month,docdate),13)as [Month],
bdr_hfl as Amount
FROM gbkmut gl left outer join grtbk acct on gl.reknr = acct.reknr
where docdate between '2016-01-01' and '2016-10-31'
)
as TB
PIVOT
(
SUM(Amount)
FOR [Month] IN (January, February, March, April,
May, June, July, August, September, October, November, December)
)
AS PVT
order by [GL Account] asc
How can I add 1 more column 'Balance' that is the total of every month's Amount? Basically a Trial Balance query with the YTD balance as a column unto itself?
Thank you.
SELECT *
FROM (
SELECT
gl.reknr as [GL Account], oms25_0 as [Description], left(datename(month,docdate),13)as [Month],
bdr_hfl as Amount
FROM gbkmut gl left outer join grtbk acct on gl.reknr = acct.reknr
where docdate between '2016-01-01' and '2016-10-31'
)
as TB
PIVOT
(
SUM(Amount)
FOR [Month] IN (January, February, March, April,
May, June, July, August, September, October, November, December)
)
AS PVT
order by [GL Account] asc
How can I add 1 more column 'Balance' that is the total of every month's Amount? Basically a Trial Balance query with the YTD balance as a column unto itself?
Thank you.