473,326 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Running Balance with Data Containing NULL

I need to calculate running balance on data containing Null, which is sorted by few columns.
As example below, Clr is sorted by Null Desc, then by date, then just by ID.
So far, I just come out with this...

SELECT tr1.Clr, tr1.ID, tr1.Date, tr1.Acc, tr1.Dbt, tr1.Cdt, (SELECT SUM(Nz(tr2.Dbt) - Nz(tr2.Cdt)) FROM tbl00 AS tr2 WHERE (tr2.Acc = tr1.Acc AND tr2.Clr <= tr1.Clr)) AS Bal
FROM tbl00 AS tr1
WHERE (((tr1.Acc)=12345) AND ((tr1.Audit)=True))
ORDER BY tr1.Clr, tr1.Date, tr1.ID;

this query can give me the running balance for all data in Clr column not NULL, but when it come to null, the calculation stopped.

Clr Date ID Acc Dbt Cdt Bal
----------------------------------------------------------------------------------------------------------------
1 15/10/08 503 12345 100.00 NULL 100.00
2 14/10/08 504 12345 NULL 3.00 97.00
3 16/10/08 499 12345 NULL 150.00 -53.00
4 16/10/08 505 12345 200.00 NULL 147.00
5 18/10/08 506 12345 NULL 2.00 145.00
NULL 18/10/08 500 12345 1.00 NULL 146.00
NULL 19/10/08 499 12345 NULL 5.00 141.00

i was also trying to break the result into 2 sql which 1 as above, calculate all the non-NULL result and another sql to calculate the remaining that contain NULL in Clr. In these tries, i trying to add a sequence column to replace the NULL in Clr column, but also unsuccessful.

Any one can give me a hand???
Nov 11 '08 #1
0 1364

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: paul | last post by:
I have a query that takes monthly totals and rolls them up to get a balance at a specific time code eg: dt bucket mon_ttl --- ------ ------- 199903 ...
4
by: Thomas Paul Diffenbach | last post by:
Can anyone point me to an open source library of /statically allocated/ data structures? I'm writing some code that would benefit from trees, preferably self balancing, but on an embedded system...
5
by: bobdydd | last post by:
Hi Guys Can anyone help I am trying to find a way to implement a running balance that will re-calculate if the date order is changed, or if an earlier record is changed like you might want to do...
4
by: Rose | last post by:
A newbie question: I would like my repeater to look like the following where in the Balance column, I want to keep a running balance, like so Description Amount Balance Item 1 $10 ...
1
by: Tom Brown | last post by:
I have a report I created which pulls all data by month by category and gives me running totals month by month. My problem is I need the ending balance running total to move down to the next line...
13
by: Maria Mela | last post by:
Hello everyone... Anybody can help me on this question, please? i´ve this code in my application: /*for Card creation*/ typedef struct card { etc,etc } Card; typedef Card *PtrCrt;
1
by: BrianMiller | last post by:
I have searched for an answer but have failed to come up with anything that seems to work. I am trying to set up an Access 2003 database for home accounts. I want to create a running sum (a...
3
by: Paul H | last post by:
I have a transactions table and a balance table that look something like this: tblTransactions TransactionID (PK Autonumber) ClientID TransactionDate TransactionAmount (currency field, values...
1
by: darendaren88 | last post by:
I have created this table: mysql> describe acount; +----------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra |...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.