Microsoft Access Forums

Go Back   Microsoft Access Forums > Access Forums > Queries

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 11-11-2008, 05:50 PM
Novice
 
Join Date: Nov 2008
Posts: 2
dustonheaven is on a distinguished road
Default HELP NEEDED: 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???
Reply With Quote
  #2  
Old 11-12-2008, 10:03 AM
jya jya is offline Windows XP Access 2007 (version 12.0)
Competent Performer
 
Join Date: Sep 2007
Location: Chicagoland
Posts: 109
jya is an unknown quantity at this point
Default

Perhaps I am missing something. What about having the Dbt and Cdt fields default to 0 or using Nz(tr2.Dbt,0)?
Reply With Quote
  #3  
Old 11-12-2008, 02:36 PM
Novice
 
Join Date: Nov 2008
Posts: 2
dustonheaven is on a distinguished road
Default

Perhaps I am the one who miss something, some more detail in my question.
Actually, Nz is not the problem here. The calculation of BAL can be generate correctly, for the data where CLR is not NULL, but it stop after CLR reach NULL (since I sort Null value DESC). After CLR is NULL, I let the data sorted by DATE, then by ID. For this I try to add argument in (tr2.Acc = tr1.Acc AND tr2.Clr <= tr1.Clr) to continue the calculation, but of course, I failed.....
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help needed desperately tinyuna Access 0 05-03-2007 12:18 AM
not correct running total in group cmk Reports 1 12-06-2006 02:56 PM
Running Queries from a form HaYuM Queries 0 06-13-2006 07:48 AM
Txt box on form showing 'Balance' wasim_sono Programming 1 04-25-2006 03:58 AM
Adding Running Balance from Form to Reports KIDGEO3 Reports 1 01-18-2006 05:52 AM


All times are GMT -8. The time now is 10:26 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.