| Author |
Topic |
|
cujee75
Starting Member
2 Posts |
Posted - 2008-02-27 : 00:00:27
|
| I've created SQL statement to display data that include Project ID, WBS Element, DebitTotal, CreditTotal, Net (net figure is sum between DebitTotal and CreditTotal = CreditTotal - DebitTotal), FiscalPeriod and FiscalYear. To display data I need to key-in the timekey. If 200702 refer to data for February 2007. The problem is, how to calculate accumulated figure for Net? I have to display YearToDate figure which is accumulated figure for every month for Net table. e.g Net for February is 1000, March is 2000. YearToDate should be 3000 (1000+2000).Another problem is because I'm using the timekey to display the data, table name is the same for every month. How to accumulate the Net figure? Please help. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-27 : 00:06:14
|
| Can you provide me your sample data with table structure? |
 |
|
|
cujee75
Starting Member
2 Posts |
Posted - 2008-02-27 : 01:22:49
|
| SQL query is :select Indicator, Project, Timekey, sum(Debit) As TotalDebit, sum(Credit) As TotalCredit, sum(Debit)-sum(Credit) As Netfrom @TotalTempgroup by Indicator,Project, TimeKeyhaving CAST(TimeKey As varchar) = @TKey and Substring (Indicator,1,4) = 'REV-'order by Indicator, Project, TimeKeyOutput is:February Indicator|Project|TimeKey|TotalDebit|TotalCredit |NetREV-MOB |MOB 2 |200702 |0.00 |16,347,783.00|-16,347,783.00REV-PCSB |PCSB 20|200702 |6,043,881.00|22,528,189.00|-16,484,308.00MarchIndicator|Project|TimeKey|TotalDebit|TotalCredit |NetREV-MOB |2004 |200703 |16,347,783.00|16,887,004.01|-539,221.01REV-PCSB |PCSB 2 |200703 |13,125,318.86|39,981,012.86|-26,855,694.00To get YearToDate, I have to sum Net figure for every month. Example, YearToDate = [(-16,347,783.00)+(-539,221.01)] because it came from the same project REV-MOB. If I hve Net figure for April for REV-MOB, I'll sum it as well. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-27 : 02:00:00
|
| select Indicator, Project, Timekey, sum(Debit) As TotalDebit, sum(Credit) As TotalCredit, sum(Debit)-sum(Credit) As Net into #Tempfrom @TotalTempgroup by Indicator,Project, TimeKeyhaving CAST(TimeKey As varchar) = @TKey and Substring (Indicator,1,4) = 'REV-'order by Indicator, Project, TimeKeyUpdate t1SET t1.Net=t1.Net + t2.NetFROM acct t1INNER JOIN acct t2on t2.Indicator=t1.Indicatorand t2.TimeKey<t1.TimeKeyselect * from t1 |
 |
|
|
|
|
|