UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Count in Query    
 
   
DAPPayroll
post Feb 9 2007, 07:18 PM
Post #1

New Member
Posts: 19



I want the query to display a 0 if the count is 0. Currently, it displays nothing. How do I fix this?

Here is an example of my SQL:

SELECT Count([ExtendedPrice]) AS [CountOfExtendedPrice] FROM [Order Details Extended] GroupBy [ExtendedPrice] HAVING ((([ExtendedPrice])="100.00"));

So it counts how many times it finds extended price being 100.00

If there are no 100.00's, I want it to say 0 but it currently says nothing at all.

Any help would be greatly appreciated, thanks.
Go to the top of the page
 
+
DAPPayroll
post Feb 9 2007, 07:31 PM
Post #2

New Member
Posts: 19



as in, where does the "NZ" function go?
Go to the top of the page
 
+
GroverParkGeorge
post Feb 9 2007, 07:34 PM
Post #3

UA Admin
Posts: 19,250
From: Newcastle, WA



SELECT NZ(Count([ExtendedPrice]),0) AS [CountOfExtendedPrice] FROM [Order Details Extended] GroupBy [ExtendedPrice] HAVING ((([ExtendedPrice])="100.00"));
Go to the top of the page
 
+
DAPPayroll
post Feb 9 2007, 07:43 PM
Post #4

New Member
Posts: 19



That didn't work for me, not sure why. Let me give you my exact SQL (that was merely an example)

I am doing a survey, and they can select one of four answers for this question. I want to count how many times "not available" is selected, but if it is 0, i want it to put 0 instead of nothing.

Now keep in mind that I work for law enforcement....

SELECT Count(Contacts.[Q2a - Powder Cocaine]) AS [CountOfQ2a - Powder Cocaine]
FROM Contacts
GROUP BY Contacts.[Q2a - Powder Cocaine]
HAVING (((Contacts.[Q2a - Powder Cocaine])="Not Available"));

Thanks again!
Go to the top of the page
 
+
rabroersma
post Feb 9 2007, 07:47 PM
Post #5

UtterAccess VIP
Posts: 1,215
From: Arcadia, California, USA



The problem is that your query is not returning a null, It is actually returning an empty set (i.e. zero rows/columns returned). If you had a null return, the query would have worked.

you will have to provide more detail about the layout of your table in order to assist you with a working query.

Regards,
Richard Broersma Jr.

Edited by: rabroersma on Fri Feb 9 19:48:18 EST 2007.
Go to the top of the page
 
+
DAPPayroll
post Feb 9 2007, 07:51 PM
Post #6

New Member
Posts: 19



Ok, what do you need to know about the layout?
Go to the top of the page
 
+
rabroersma
post Feb 9 2007, 07:59 PM
Post #7

UtterAccess VIP
Posts: 1,215
From: Arcadia, California, USA



By layout I mean table definition. Knowing what columns are in your table will help in determining how to construct a outer join query. Using the outer join query, a null will be returned that can be converted to a zero for you total count.
Go to the top of the page
 
+
DAPPayroll
post Feb 9 2007, 08:03 PM
Post #8

New Member
Posts: 19



There are basically just four answers they can choose from in a drop down menu. I just am counting each selection from all the surveys
Go to the top of the page
 
+
DAPPayroll
post Feb 9 2007, 08:14 PM
Post #9

New Member
Posts: 19



Can I put an "If" statement in SQL, so that if the value is null, it will put a 0?
Go to the top of the page
 
+
rabroersma
post Feb 9 2007, 08:16 PM
Post #10

UtterAccess VIP
Posts: 1,215
From: Arcadia, California, USA



What are the tables that you are using to populate the drop down menu box?

Edited by: rabroersma on Fri Feb 9 20:22:17 EST 2007.
Go to the top of the page
 
+
rabroersma
post Feb 9 2007, 08:17 PM
Post #11

UtterAccess VIP
Posts: 1,215
From: Arcadia, California, USA



An IF has the same problem as the NZ. It can't act on a emptyset. It needs a null (at the very minimum) to operate on.
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 25th May 2013 - 05:38 AM