Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

When query returns null, I need a zero value as results are used in another query

Posted on 2004-10-26
7
Medium Priority
?
232 Views
Last Modified: 2010-04-17
I have looked over the answers to what seems to be this question, but do not get them to work.  What I have is a query that if there are no rows to count, does not give me any return value, ie., Null.  However, the results of this query are used in another query and I must have a zero value-otherwise the second query gives me all nulls for the other fields in it despite the fact that their base queries do return values.

SELECT IIf(IsNull(Count([tblDocumentsReturned].[Account])),0,(Count([tblDocumentsReturned].[Account]))) AS MutualFund
FROM tblDocumentsReturned
WHERE (((tblDocumentsReturned.DateReceived)<=[FORMS]![frmMatrixDialog]![txtEnd]) AND ((tblDocumentsReturned.DocStatus)="Mutual Fund"))
GROUP BY tblDocumentsReturned.Product
HAVING (((tblDocumentsReturned.Product)=[FORMS]![frmMatrixDialog]![lstProduct]));

Thanks
0
Comment
Question by:ssmith94015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Expert Comment

by:EagleEye1975
ID: 12414795
There should be a few ways around this, but we really need to know what development environment you're using.

There should be a way to get the number of rows returned by the query... that's the first type of function I'd look for.

If there is no such function, you can do an error trap, saying "If (whatever) = null, NumRows = 0"

That way, your NULL becomes a zero, and that later function doesn't work with a bunch of NULL values.
0
 

Expert Comment

by:BillJennings
ID: 12442496
I'm guessing this is MS-Access.

It looks to me like this query returns a row for each record from tblDocumentsReturned that meets the criteria, and each of these rows contains a single field (called MutualFund) containing the total number of rows in tblDocmuentsReturned.

Now,  I'm not sure where you want the zero to be returned.  If there are no rows in tblDocumentsReturned that meet the criteria, it will not return any rows.  Do you want it to always return at least one row?  If so, where would the zero go?

Sincerely
Bill Jennings
0
 
LVL 2

Expert Comment

by:EagleEye1975
ID: 12460124
Are you going to give more information or accept an answer?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:ssmith94015
ID: 12464567
Sorry, I have been out of the office, but am glad for the responses.  What I have is another query based on the results of multiple count queries that combines all these results to be used in a final report.  
0
 

Author Comment

by:ssmith94015
ID: 12464575
I am using Access mdb database
0
 
LVL 2

Accepted Solution

by:
EagleEye1975 earned 1000 total points
ID: 12465412
Yeah, it's pretty simple then...

All of those count queries need to say "If count = null then count = 0"... so that when they're added together you're not trying to add null, you're adding zero instead.

Add a layer of abstraction in... don't use the count query results themselves in the adding up of the total.  Do the count queries, and have each result be evaluated and put a final result in to a variable (this would all be done in a module)... then evaluate the variables... if null, then make them equal zero instead... add the result variables, and you have your total without nulls. :)
0
 

Expert Comment

by:BillJennings
ID: 12485765
BTW

"if [count] == null then [count] = 0" can be done inside the query with:

cnt: nz([count])

then use [cnt] wherever you were going to use [count].

Sincerely

Bill Jennings
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Simple Linear Regression

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question