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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-03-15 : 07:54:45
|
| hoshang writes "i have table with trid,pay_in,pay_out what i want is how to calculate the current_balance at each record,e.g .. i want to select trid,pay_in,pay_out, (Some kind of calculation to get the current_balance ) as current_balancei want to have the following resultitd : payin : payout : current_balance1 : 2000 : 0 : 2000 2 : 0 : 1000 : 1000 3 : 50 : 0 : 1050---I realy need your helpthanks" |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-03-15 : 07:59:09
|
| [code]select itd, payin, payout, (select sum(payin - payout) from yourtable x where x.itd <= t.itd) as current_balancefrom yourtable t[/code]----------------------------------'KH' |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-03-15 : 08:08:42
|
| Where do you want to show the data?I think you need to make use of Reports and its Running Total feature. Doing this in SQL, can lead to performance problems if there are millions of records in the tableMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|