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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Value from previous row

Author  Topic 

pyu.agrawal
Starting Member

29 Posts

Posted - 2009-04-14 : 13:05:13
I have got two tables:
Table 1: Inwards
ID | InDate | InwardAmount | ... 


Table 2: Outwards
ID | OutDate | OutwardsAmount | ... 


I need the following output:
Date | Debit | Credit | TotalAmount | ... 


This output would be having entried from both the tables.
Date -> InDate / OutDate
Debit -> InwardAmount [from Inwards]
Credit -> OutwardsAmount [from Outwards]
TotalAmount -> ??

Calculation of TotalAmount is a bit tricky:
TotalAmount = Balance - debit + credit

If the month is April [start of fiscal year] then
Balance = 0 else
Balance = Balance - debit + credit [of the previous entry]

asgast
Posting Yak Master

149 Posts

Posted - 2009-04-15 : 03:33:11
I suspect that you are talking about running total

http://www.sqlteam.com/article/calculating-running-totals
Go to Top of Page
   

- Advertisement -