Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Totals in a Union Query

Author  Topic 

daisyrock
Starting Member

1 Post

Posted - 2009-11-24 : 05:04:01
I am hoping someone can help me here.

This is my first post after registering so hello to all :)


I am looking to add some information to a query/report

1 is 'YTD' which will SUM all ACTUAL_AMOUNTS for all periods except 00.

The other is 'closing balance' which is a grand total/SUM all ACTUAL_AMOUNTS

It has taken me ages to get the query right and now i am not sure where to start entering my last 2 requirements as i built the query using help from this site and am only sql beginner.

Here is it

SELECT FISCAL_PERIOD, round(SUM(ACTUAL),0) as ACTUAL_AMOUNT FROM
(select SUM(T1.TRANSAMNT) AS ACTUAL, T1.PERIOD AS FISCAL_PERIOD from xxx.LEDGER T2, xxx.G_LDETAIL T1
where T2.ACCOUNTNO=T1.ACCOUNTNO and T2.PARENT_LEVEL4='xxxxx' and T1.FISCAL_YEAR=2009
group by T1.PERIOD

UNION ALL

select SUM(T1.TRANSAMNT) AS ACTUAL, T1.PERIOD AS FISCAL_PERIOD from xxx.LEDGER T2, xxx.G_LTRANS T1
where T2.ACCOUNTNO=T1.ACCOUNTNO AND T2.PARENT_LEVEL4='xxxxx' AND T1.FISCAL_YEAR=2009
group by T1.PERIOD)

TEMP

GROUP BY FISCAL_PERIOD

Any advice would be sincerely appreciated.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-11-27 : 02:31:17
sorry your post is not clear. can you show some sample data to illustrate your scenario please?
Go to Top of Page
   

- Advertisement -