Solved

Show 0 when Count is Zero

Posted on 2011-03-14
6
563 Views
Last Modified: 2012-06-21
I am getting a count of Records.

What I need to add is, if the count is zero or null  then show the zero has count.

SELECT Count(M_AS400_P112.PCode) AS CountOfPCode, M_AS400_P112.MaintenanceDate, M_AS400_P112.PCode INTO TodayCountAS400P112
FROM M_AS400_P112
GROUP BY M_AS400_P112.MaintenanceDate, M_AS400_P112.PCode;

Open in new window

0
Comment
Question by:ca1358
6 Comments
 
LVL 9

Expert Comment

by:sshah254
ID: 35130600
MSSQL has ISNULL ... check for something similar for the AS400.

Ss
0
 

Author Comment

by:ca1358
ID: 35130690
I need syntax of Count(Field) but iif isNull then put a zero.
0
 
LVL 75
ID: 35130742
Maybe this:

SELECT Count( Nz(M_AS400_P112.PCode , 0 ) ) AS CountOfPCode, M_AS400_P112.MaintenanceDate, M_AS400_P112.PCode INTO TodayCountAS400P112
FROM M_AS400_P112
GROUP BY M_AS400_P112.MaintenanceDate, M_AS400_P112.PCode;

mx
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 35130912
With no criteria specified, why would the count be zero?
Just curious...?
In other words, what is this query seeking to display?


If there are many PCode, then you should include this table in the query.
Then set a left Join to show all records from the PCode table.

Something like this to get a count of all orders for each employee, while displaying Zero for any employee with no orders:
SELECT Count(Orders.OrderID) AS CountOfOrderID, Employees.EmployeeID
FROM Employees LEFT JOIN Orders ON Employees.EmployeeID = Orders.EmployeeID
GROUP BY Employees.EmployeeID;

Sample DB with query attached

Database48.mdb
0
 

Author Closing Comment

by:ca1358
ID: 35141895
Thank you
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 35142250
OK
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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