473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Record Not Showing in Query When One Field Contains No Value

9
I have a query based on three other queries. There are four fields in this query. These are the fields:

CUSTOMER ID joins all three queries on which the query is based. The customer ID.

OVER30 displays the total outstanding amount that hasn't been paid by a customer in over 30 days.

CURRENT displays the total current outstanding for each customer for orders made within the current month.

TOTAL displays the ultimate total of OVER30 and CURRENT so it's a calculated field that simply adds the values from the two previous fields.

My problem is certain customers have no value/record for OVER30 because they're good customers. I still expect to see a record of them in the query because they do have a value/record in CURRENT (record displayed in the query from which I draw this field). However, there is no record of them in the query. Records only exist for customers with values/records in both OVER30 and CURRENT.

Keeping in mind that the values in OVER30 and CURRENT are results of two other queries, what would be the solution to this problem?

Here is the query in SQL:

Expand|Select|Wrap|Line Numbers
  1. SELECT [Q ACCOUNT ITEMS].[CUSTOMER ID], [Q ACCSTAT11].OVER30, [Q ACCSTAT22].CURRENT, [OVER30]+[CURRENT] AS TOTAL
  2. FROM [Q ACCSTAT11] INNER JOIN ([Q ACCSTAT22] INNER JOIN [Q ACCOUNT ITEMS] ON [Q ACCSTAT22].[CUSTOMER ID] = [Q ACCOUNT ITEMS].[CUSTOMER ID]) ON [Q ACCSTAT11].[CUSTOMER ID] = [Q ACCOUNT ITEMS].[CUSTOMER ID]
  3. GROUP BY [Q ACCOUNT ITEMS].[CUSTOMER ID], [Q ACCSTAT11].OVER30, [Q ACCSTAT22].CURRENT, [OVER30]+[CURRENT];
  4.  
Mar 15 '16 #1

✓ answered by MikeTheBike

Hi

You need to use an outer join which would be either a Left Join or RIGHT JOIN, depending on the order of the tables in the query.
In this case it would suggest something like this
Expand|Select|Wrap|Line Numbers
  1. SELECT [Q ACCOUNT ITEMS].[CUSTOMER ID], Nz([Q ACCSTAT11].[OVER30],0) As OVER30, [Q ACCSTAT22].[CURRENT], Nz([Q ACCSTAT11].[OVER30],0)+[Q ACCSTAT22].[CURRENT] AS TOTAL
  2. FROM [Q ACCSTAT11] RIGHT JOIN ([Q ACCSTAT22] INNER JOIN [Q ACCOUNT ITEMS] ON [Q ACCSTAT22].[CUSTOMER ID] = [Q ACCOUNT ITEMS].[CUSTOMER ID]) ON [Q ACCSTAT11].[CUSTOMER ID] = [Q ACCOUNT ITEMS].[CUSTOMER ID]
  3. GROUP BY [Q ACCOUNT ITEMS].[CUSTOMER ID], [Q ACCSTAT11].[OVER30], [Q ACCSTAT22].[CURRENT], Nz([Q ACCSTAT11].[OVER30],0)+[Q ACCSTAT22].[CURRENT];
  4.  
This will return all the common records from [Q ACCOUNT ITEMS] and [Q ACCSTAT22] and the relevant records from [Q ACCSTAT11]. Where there is no record in [Q ACCSTAT11] a null value will be returned, this is changed to a zero by the Nz() function.
HTH

MTB

2 880
MikeTheBike
639 Expert 512MB
Hi

You need to use an outer join which would be either a Left Join or RIGHT JOIN, depending on the order of the tables in the query.
In this case it would suggest something like this
Expand|Select|Wrap|Line Numbers
  1. SELECT [Q ACCOUNT ITEMS].[CUSTOMER ID], Nz([Q ACCSTAT11].[OVER30],0) As OVER30, [Q ACCSTAT22].[CURRENT], Nz([Q ACCSTAT11].[OVER30],0)+[Q ACCSTAT22].[CURRENT] AS TOTAL
  2. FROM [Q ACCSTAT11] RIGHT JOIN ([Q ACCSTAT22] INNER JOIN [Q ACCOUNT ITEMS] ON [Q ACCSTAT22].[CUSTOMER ID] = [Q ACCOUNT ITEMS].[CUSTOMER ID]) ON [Q ACCSTAT11].[CUSTOMER ID] = [Q ACCOUNT ITEMS].[CUSTOMER ID]
  3. GROUP BY [Q ACCOUNT ITEMS].[CUSTOMER ID], [Q ACCSTAT11].[OVER30], [Q ACCSTAT22].[CURRENT], Nz([Q ACCSTAT11].[OVER30],0)+[Q ACCSTAT22].[CURRENT];
  4.  
This will return all the common records from [Q ACCOUNT ITEMS] and [Q ACCSTAT22] and the relevant records from [Q ACCSTAT11]. Where there is no record in [Q ACCSTAT11] a null value will be returned, this is changed to a zero by the Nz() function.
HTH

MTB
Mar 15 '16 #2
Zacko
9
Thanks a lot, Mike. It worked perfectly. I now have what I want and have used the query to make a subform and will be making a subreport in the same way. Thank you!
Mar 16 '16 #3

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

Similar topics

3
by: William Wisnieski | last post by:
Hello Everyone, Access 2000, I have a main unbound form with a bound datasheet subform . The subform is bound to a query that returns records based on criteria in the main form. The user...
13
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to...
1
by: John Baker | last post by:
Hi; Dumb question, but I have a query and i want to accept the record if a field is blank. I have tried criteria of ="", isempty(Fieldame) and a rich variety of other things with no joy. How do...
8
by: Dennis C. Drumm | last post by:
I have a class derived from a SortedList called SystemList that contains a list of objects indexed with a string value. The definition of the objects contained in the SortedList have a boolean...
31
by: MRHIGHSPEED | last post by:
Hi all. I'm new here and fairly new to building databases. Learned a lot in designing this one, but I am stuck on this one last expression. I'm trying to create a calculated control. The form is...
2
by: fperri | last post by:
Hello, I have a query that creates a table of duplicates in my database. For one set of duplicates (three records), all the fields & values are the same except for the values in one field. This...
11
by: captainphoenix | last post by:
In VB (.NET?) building a query from a table made in MS Access. I'm trying to type the sql line WHERE = @ but it won't recognize the code because "Course Number" is two words. the whole thing...
4
by: mashimaro | last post by:
Hi! I want to ask how can I get the record from the query. I currently have a form with 5 comboboxes and a button. After the user fills those 5 comboboxes and hit the button, a new form is opened...
5
by: ladybug76 | last post by:
Hi. I'm working on a database and I though I tinker with Macros and VB, I am not very versed in them. So ANY help would be HUGELY appreciated!!! (I'm using Access 2003) What I need to do...
3
by: Becker | last post by:
I have a form "Finish" which has a record source "finish query". Criteria for the query is that they must enter an item # to view only that record at that time. I want them to be able to just type...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...

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.