473,511 Members | 14,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Addition expression that handles null values

5 New Member
Hi,

I am trying to write an expression that will add two fields that sometimes can contain Null values. Retaining the 'null' aspect is important because I need to know when no data at all was recorded for a particular row.

At first I tried this code:

Expand|Select|Wrap|Line Numbers
  1. LY34_SUB1: Nz([LY3_TREE_SUB1],0)+Nz([LY4_TREE_SUB1],0)
However, if both fields are Null then it spits back 0. I want it to stay null.

So I tried adding an iif statement to my expression where if the above code was equal to 0 then the TRUE condition of the Iif statement would be a NULL and FALSE would be the sum of the two values with 0's substituted in using the Nz function.

Expand|Select|Wrap|Line Numbers
  1. LY34_SUB1: Iif(Nz([LY3_TREE_SUB1],0)+Nz([LY4_TREE_SUB1],0)=0),Null,Nz([LY3_TREE_SUB1],0)+Nz([LY4_TREE_SUB1],0)]
This still doesn't work. Suggestions?

Thanks,

Gerry
Nov 12 '13 #1
5 1263
CJ_London
27 New Member
not tested but have you tried

Expand|Select|Wrap|Line Numbers
  1. LY34_SUB1: Iif(isnull([LY3_TREE_SUB1]) and isnull([LY4_TREE_SUB1]),[LY3_TREE_SUB1],Nz([LY3_TREE_SUB1],0)+Nz([LY4_TREE_SUB1],0))
Nov 12 '13 #2
gaf44
5 New Member
Thank you, "CA in the UK". That worked well. I appreciate the help. Best regards, Gerry
Nov 12 '13 #3
CJ_London
27 New Member
as a newcomer, I'm pleased to help
Nov 13 '13 #4
NeoPa
32,557 Recognized Expert Moderator MVP
An alternative :
Expand|Select|Wrap|Line Numbers
  1. LY34_SUB1: IIf([LY3_TREE_SUB1]+[LY4_TREE_SUB1] Is Null,Null,Nz([LY3_TREE_SUB1],0)+Nz([LY4_TREE_SUB1],0))
NB. This doesn't mean there is anything wrong with CA's code or approach. It simply illustrates an alternative way of looking at it.
Nov 14 '13 #5
gaf44
5 New Member
Hey, Thanks NeoPa!
Nov 14 '13 #6

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

Similar topics

1
3024
by: Marcus | last post by:
Hello, quick question about MySQL storing NULL values... Say I have a textbox called $_POST and a variable $var. if(empty($_POST)) $var = NULL; else $var = $_POST; Disregarding...
6
3178
by: Tino Wildenhain | last post by:
Hi, SELECT 'abc'::text || 'def'::text; returns 'abcdef' as we know. SELECT 'abc'::text || ''::text; returns 'abc'
6
5254
by: AAVF | last post by:
Hi We have a problem with a query. An Access database links via ODBC to a UNIX server. To speed things, we use the ODBC to load the relevant tables to the local PC that runs Access so that...
3
11468
by: John | last post by:
I've read several prior posts in this group about using nz() to convert null values to zero; however, I'm not sure how/where to implement this function in my crosstab query. The crosstab query...
5
6472
by: Doc Skylab the uber surgeon | last post by:
Hello, Please could you help with the following: I would like to change the null values on a query result and/or table to zero so I can perform calculations. At the moment, I cannot...
1
2461
by: Ken | last post by:
I wrote a function to use in queries that takes a date and adds or subtracts a certain length time and then returns the new value. There are times when my function needs to return Null values. ...
6
1980
by: Randy Rubin | last post by:
How do I handle Testing for null values in a database? Here is a Line of Code: If Not jNull("JNum") Is DBNull Then And this is the Error: BC30684: 'DBNull' is a type and cannot be used as...
5
6362
by: Neil | last post by:
I'd like to know what the best method is for handling NULL (or 0) values within a DropDownList. If a database lookup value is optional I would normally consider leaving it NULL but this leads to...
10
8997
by: Toby Gallier | last post by:
Hello! I have a form that is calculating averages as follows: " =(NZ()+Nz()+Nz())/3 " However I need to now adjust for null values , so for example if value2 is null I would then need to...
6
3683
by: gaf44 | last post by:
Hi, I am trying to create a make-table query that includes an expression which will average four fields. My problem is that the fields contain null values for certain rows. I want the...
0
7137
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...
0
7417
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...
0
7506
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
5659
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,...
0
4734
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
3219
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...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
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 ...
0
445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.