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 |
|
hardwood
Starting Member
19 Posts |
Posted - 2010-06-08 : 12:23:26
|
| There's this column in my query that contains numbers, see:selecti.Amount as Balancethe numbers are right, which is good. Is it possible, though, to add them? I know that sounds stupid (think sum function), but I mean add them in a way that every new row adds from the row before it, such as below:Currently like this:row 1 = 600row 2 = 400row 3 = -300...Need it to be like this:row 1 = 600row 2 = 400+(row1) = 1000row 3 = -300+(row2) = 700... |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2010-06-08 : 12:48:00
|
| This is known as a running total, and should be done in your front end.http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
hardwood
Starting Member
19 Posts |
Posted - 2010-06-08 : 15:16:02
|
quote: Originally posted by DonAtWork This is known as a running total, and should be done in your front end.http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp
But how would I do it for this syntax? I removed all the other fields that need to be shown and am only SELECTing the one that needs to be running total'd:Selecti.Amount as 'Balance'FromARHeader hjoin ARDetail d on h.Voucher = d.Voucher and h.CompCode = d.CompCodejoin ARItem i on d.[LineNo] = i.[LineNo] and d.Voucher = i.VoucherWherei.CompCode='Will' and h.AID=475568982 and d.TransNo=0I tried a bunch of subqueries but I can't seem to find the right syntax to get the right answer |
 |
|
|
|
|
|