473,503 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems dividing by a null value to find a percentage

3 New Member
I have a query the rolls up a qty recieved per month and a qty rejected per month and then calculates a right the first time percentage by simply 1-(qty rejected/qty received). Work fine unless I have a month where there are no rejects. Instead of return 100% the field is just blank. I can use the same method in an Excel sheet and it calculates the percentage as 100% even with the dividor blank, but in my Access Query it just returns a blank for that month. I have an attachment to this post that shows the query. What am I missing?
Attached Images
File Type: jpg Divide by Null.jpg (121.4 KB, 752 views)
Mar 28 '11 #1
3 2405
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Hi Lpitt56

For more background information on null look at:
What is null?

Basicly, the problem comes from the fact that null is NOT the same as 0. Simple example. Imagine this simple example:
I hand you a black bag, and tell you there are apples inside. I dont tell you how many and you are not allowed to look. You have NULL information on the amount of apples. If I ask you to add / subtract / divide, you would still have NULL information on the result. That is similar to what is going on here.

However, sometimes we as programmers know that the absence of a value IS equal to 0. We can then convert the null to something harmless, for instance a 0. This can be done by the Nz function (READ THE Access help on it)
Expand|Select|Wrap|Line Numbers
  1. Nz(Variable, ALTERNATE_Variable)
If variable is NULL, it will return the ALTERNATE_Variable.

Example usage in your case:
Expand|Select|Wrap|Line Numbers
  1. 1-(nz(qty rejected,0)/qty received)
Mar 28 '11 #2
Lpitt56
3 New Member
Thanks for the info! Your reccomendation worked great!
Mar 30 '11 #3
TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Your welcome. Glad to hear it worked for you.
Mar 30 '11 #4

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

Similar topics

3
27739
by: John Morgan | last post by:
In an SQL statement which concatenates several fields I get a null value returned if any one of the fields are null. Is this to be expected? For example : SELECT tblMember.memberAddress + '...
12
4870
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same...
4
11756
by: Tom Esker | last post by:
I've got Javascript in a form that adds up all of the numbers in a column of form fields and displays a total. It works great if every field has an initial value of 0, but if any of them are null,...
1
28473
by: Pekka Henttonen | last post by:
For some reason SQL0407N error messages never reveal the name of the column to which a NULL value has been assigned. Here is an example: SQL0407N Assignment of a NULL value to a NOT NULL column...
4
2029
by: Mark Hanley | last post by:
I have found similar problems to mine on this and other newsgroups but I still haven't been able to solve my problem... I have two tables 'Pupil' and 'SEN' which are related on a field called...
1
1884
by: excelleinc.com | last post by:
Hi, I'm trying to check if field contains NULL value in MSSQl 2000 database but keep receiving error. asp.net code: If Trim(HLSQLDSet.Tables("mfglinks").Rows(15).Item(0)) Is Null Then...
15
29191
by: TC | last post by:
What does it mean for an integer to have a null value? I am trying to use the DataView.Find method. That method has an integer return type which contains the "index of the row in the DataView...
1
1041
by: Ranjan as usual | last post by:
Dear folks, I'm programming in VB .net and trying to import values from fields in a table in SQL. Everytime there is a NULL value in SQL, the program doesn't work and shows an error. How does VB...
1
10310
by: Smitty | last post by:
From the psql command line, I am having absolutely no problems inserting a NULL value into a date datatype field. When attempting to insert a NULL value via my Web app using SQL Relay, I am...
26
30886
by: Martin R | last post by:
Hi, How to find first not null value in column whitout chacking whole table (if there is a not null value then show me it and stop searching, the table is quite big)? thx, Martin *** Sent...
0
7280
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,...
0
7332
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...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
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...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
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 ...

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.