473,473 Members | 4,204 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Handling Null Values in Access Query

58 New Member
I previously wrote the following query which gives me that data I wanted and currently returns 436 records:
Expand|Select|Wrap|Line Numbers
  1. SELECT qryTonnageSelect.Jobs_Job_ID, qryTonnageSelect.SumOfTransactions_TonsNetWeight, qryProfitability.Margin, jcjob.name, qryProfitability.SumOfcost, qryProfitability.SumOfSumOfcost, qryProfitability.DollarMargin
  2. FROM (qryTonnageSelect INNER JOIN qryProfitability ON qryTonnageSelect.Jobs_Job_ID = qryProfitability.jobnum) INNER JOIN jcjob ON qryProfitability.jobnum = jcjob.jobnum
  3. ORDER BY qryTonnageSelect.Jobs_Job_ID;
I would now like to add another field (man hours) that comes from a subquery. I'm running into a problem in that if the subquery does not have a value of man hours (SumOfSumOfhours) for for the above query for a particular record then the whole record is not returned and it cuts my data down to only 202 records.

I would prefer it keep the record and either leave the field null or replace it with a 1. Is there a way to do this. The following is the state of the query when I became stumped. Please help. Thank you.
Expand|Select|Wrap|Line Numbers
  1. SELECT qryTonnageSelect.Jobs_Job_ID, qryTonnageSelect.SumOfTransactions_TonsNetWeight, qryProfitability.Margin, jcjob.name, qryProfitability.SumOfcost, qryProfitability.SumOfSumOfcost, qryProfitability.DollarMargin, qryPaverHourGroupforTonsRep.SumOfSumOfhours
  2. FROM ((qryTonnageSelect INNER JOIN qryProfitability ON qryTonnageSelect.Jobs_Job_ID = qryProfitability.jobnum) INNER JOIN jcjob ON qryProfitability.jobnum = jcjob.jobnum) INNER JOIN qryPaverHourGroupforTonsRep ON qryTonnageSelect.Jobs_Job_ID = qryPaverHourGroupforTonsRep.jobnum
  3. ORDER BY qryTonnageSelect.Jobs_Job_ID;
Jan 15 '08 #1
3 3955
puppydogbuddy
1,923 Recognized Expert Top Contributor
You can wrap your manhours with the nz (null to zero) function as shown below. If you don't want the nulls to convert to zero, you can replace the null with a 1 instead.
Expand|Select|Wrap|Line Numbers
  1. nz(qryPaverHourGroupforTonsRep.SumOfSumOfhours, 0)  <<converts nulls to 0
  2.  
  3. nz(qryPaverHourGroupforTonsRep.SumOfSumOfhours, 1)  <<converts nulls to 1
Jan 15 '08 #2
NeoPa
32,556 Recognized Expert Moderator MVP
As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use the tags in future.

ADMIN.
Jan 15 '08 #3
NeoPa
32,556 Recognized Expert Moderator MVP
I think in this case (Nz() is very useful for working with Nulls) that you need to look at your joins. A full INNER JOIN to the subquery will select only those records which have matching values in the fields linked on. IE. They exist on BOTH sides of the JOIN.
You should consider using a LEFT JOIN instead.

PS. I would have tried to look at the SQL but it doesn't even seem to have any Man Hours field in it so I'd just be guessing what you are doing.
Jan 15 '08 #4

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

Similar topics

1
by: Larry Peeters | last post by:
Hi, I have created a very simple query to link two tables on 4 fields. However, in certain cases, one of the fields used to link the table may contain nulls (in both tables, so this should still...
6
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
by: JOEP | last post by:
What do I need to do to allow an append query to post null values to records in a field of the destination table? Basically I want to allow records with null values to post to the table. The append...
12
by: jkearns | last post by:
Hello, I made a report from a crosstab query following the steps onlined in MSDN's Solutions.mdb example. I now have a dynamic crosstab report (great!), but with one minor problem. I cannot get...
1
by: DKode | last post by:
I find myself writing repetitive functions for handling null values from my DB like so: Private Function SetDateNull(ByVal p_date As Object) As Date If (TypeOf (p_date) Is System.DBNull) Then...
4
by: Rob | last post by:
Hey all, So.. a simple FormView/SqlDataSource to handle inserting records into a table. The table has a primary key that the user enters (eg DiscountCode). If the user enters a duplicate the...
8
by: salad | last post by:
I was wondering how you handle active/inactive elements in a combo box. Let's say you have a combo box to select an employee. Joe Blow has been selected for many record however Joe has left the...
4
by: anisu | last post by:
Hi, I am trying to do error handling during insert in MS Access 2002 (OS: MS XP) The problem is that when a duplicate record is added for the primary key field or a null value included in a...
2
by: andyehi | last post by:
Hi My application will select and read records using datareader from mysql table and do insert or update on access data base.My problem is when I set the mdb database to allow zero length string...
0
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,...
0
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
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
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
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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
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.