473,657 Members | 2,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Running Balance with Data Containing NULL

1 New Member
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)=123 45) AND ((tr1.Audit)=Tr ue))
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 1389

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

Similar topics

3
5090
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 0192 -172527 199906 0192 546707 199909 0192 -278684 199910 0192 1100139
4
3854
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 that doesn't offer dynamic memory allocation (to be clear: no malloc, no realloc), and with rather tight memory constraints. Writing my own malloc to do dynamic allocation from some static pool isn't really an option, for various reasons, not...
5
6774
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 during a bank statement reconcile. I am using the following fields Date|Payment|Deposit|Running_Balance (tblTransactions)
4
2685
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 $10 Item 2 $15 $25 Item 3 $5 $30 Essentially, Balance = Balance + Amount for each row. I want to do this in a
1
2112
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 in the report as a beginning balance. How can I set that up in the report? I also need to put a zero in the Jan06 Beginning Balance column. Example: Period Begin Bal Accruals Pymts Rcls WO ...
13
1985
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
2743
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 balance based on what has been spent or paid in). I have a table called tblCardBankPymnts. In that I have a Figure column for what transaction has been done. I also have a Balance column but think I should not have this now. I then have a form to...
3
5175
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 must be >0) CRDR (indicates whether the transaction is a (credit or debit) StatementDate (Date stamp applied when the “Statement” report is run)
1
2537
by: darendaren88 | last post by:
I have created this table: mysql> describe acount; +----------+---------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------+---------------+------+-----+---------+----------------+ | uniqueID | bigint(20) | NO | PRI | NULL | auto_increment | | amount | decimal(20,0) | NO | | NULL | | | BALANCE | decimal(20,2) | NO | |...
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.