473,395 Members | 1,658 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,395 software developers and data experts.

Why doesn't Query show zero for records that don't fit my criteria?

I'm trying to build an Access Query that will give me the year and the total catch, even if there was no catch. The problem is if there was no catch for a certain year the query is not showing that year.

I've attached a picture of the query criteria. I've tried multiple things to get it to show all the years (should be back to 1952, but it's only showing back to the first in-river data in Area 29 which is my critieria I specified). Why won't it show a 0 for all the other years that don't fit my criteria?

I hope this isn't too confusing. Can someone help?????
Attached Images
File Type: jpg query problem.jpg (9.6 KB, 300 views)
Nov 9 '09 #1

✓ answered by missinglinq

@msquared
Actually, you really don't, if you're willing to settle for the Default. I didn't try this with an aggregate function, but assuming Field1 and Field2 are defined as Numbers, and

Field1 = 10

and

Field2 is Null

Nz(Field1) + Nz(Field2)

will yield 10, not a Null.

Access looks at the Datatype of the underlying field in question, and assigns an appropriate value if the argument is left blank.

If the Datatype is Number it assigns a zero.

If the Datatype is Text it assigns a zero length string.

Maybe I've misinterpreted the problem; the OP's question isn't terribly clear, but he does say

"Why won't it show a 0 for all the other years that don't fit my criteria?"

and if by "criteria" he means where [Marine/In-River] = "in-river" and [AreaID] = 29, then the query is not going to show records that don't meet this criteria.

Linq ;0)>

5 4185
missinglinq
3,532 Expert 2GB
The answer is very simple; if a record doesn't meet the criteria, it's not included in the query!

"I Want" says absolutely nothing about your problem here! I’ve re-titled your thread so that it actually reflects the question at hand. Having a title that does this clearly is important for two reasons.

First, it allows members, at a glance, to understand the nature of the question being asked. Thus, people who have never dealt with this or similar problems are saved the time and trouble of opening your thread. They would have nothing to contribute.

Secondly, and just as important, responsible people with questions first search for threads that address similar issues. Having a clear title facilitates these searches and saves everyone time and trouble.

Welcome to Bytes!

Linq ;0)>
Nov 10 '09 #2
MMcCarthy
14,534 Expert Mod 8TB
you used the NZ() function but left out an important element. You have to tell the function what value you want returned if null. So try this ...

Expand|Select|Wrap|Line Numbers
  1. Sum(NZ([Catch],0))
  2.  
Nov 10 '09 #3
missinglinq
3,532 Expert 2GB
@msquared
Actually, you really don't, if you're willing to settle for the Default. I didn't try this with an aggregate function, but assuming Field1 and Field2 are defined as Numbers, and

Field1 = 10

and

Field2 is Null

Nz(Field1) + Nz(Field2)

will yield 10, not a Null.

Access looks at the Datatype of the underlying field in question, and assigns an appropriate value if the argument is left blank.

If the Datatype is Number it assigns a zero.

If the Datatype is Text it assigns a zero length string.

Maybe I've misinterpreted the problem; the OP's question isn't terribly clear, but he does say

"Why won't it show a 0 for all the other years that don't fit my criteria?"

and if by "criteria" he means where [Marine/In-River] = "in-river" and [AreaID] = 29, then the query is not going to show records that don't meet this criteria.

Linq ;0)>
Nov 10 '09 #4
MMcCarthy
14,534 Expert Mod 8TB
Hi Linq :)

My understanding is that OP is looking for records to be returned that satisfy all criteria but [Catch]=null for that year. To return those records then [Catch] has to resolve to 0. That's what I think is going on anyway.

Mary
Nov 10 '09 #5
OK, I understand now that I can only get the data for the specified criteria. Sorry if I don't explain myself very well. I don't know all the terminology involved here.

The reason I was trying to get the query to show all the years, even if there was no catch, was so that I could link this table (tblCommercial) that contains catch for the years 1980-2008 with another that contained data for the years 1950-2008 (tblIFF). The tables were linked using the year field. I spent 3 days trying to get this to work before posting my question. I realize now I was focusing on the wrong problem. I should have been working on the joins between the tables in the new query. Once I made the join to show all the data from tblCommercial and only the ones from tblIff that were equal it all worked out.

Thanks to those that responded with helpful remarks. Appreciated. It always helps to discuss with other people. Cheers!
Nov 10 '09 #6

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

Similar topics

3
by: Steve | last post by:
Form FrmRestock's recordsource is QryFrmRestock. The TransactionDate field's criteria is set ats: Forms!FrmRestock!LastXDays. LastXDays on the form is a combobox where the selections are 30, 60...
3
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...
4
by: James | last post by:
Dear group, Can anyone tell me how to do the following? I have a basic list of numbers in a table I want to be able to search these by letting the user type "<10" or ">=50" on a simple form...
2
by: RBohannon | last post by:
I have a report with most fields populated by a query. However, some of the fields are variable in such a way that their values cannot be queried from a table. At present the values for these...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
12
by: strict9 | last post by:
Hello all, I'm writing several queries which need to do various string formating, including changing a phone number from (123) 456-7890. After some problem with data mismatches, I finally got it...
3
by: doar123 | last post by:
Hi, This is my basic sql shape query: ------------------------------------------------------------ SHAPE {select * from tbl1} APPEND({SELECT * FROM tbl2 where field1=1} AS RS2 RELATE field TO...
4
by: TD | last post by:
I have a form that has a frame control named fraComplaint. I have a query that I need to return records that have an empty Date_Closed field when the value of fraComplaint is 2 and all records...
22
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
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...

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.