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

x
Solved

# Show 0 when Count is Zero

Posted on 2011-03-14
Medium Priority
569 Views
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;
``````
0
Question by:ca1358
[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

LVL 9

Expert Comment

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

Ss
0

Author Comment

ID: 35130690
I need syntax of Count(Field) but iif isNull then put a zero.
0

LVL 75

Expert Comment

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

LVL 74

Accepted Solution

Jeffrey Coachman earned 2000 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

ID: 35141895
Thank you
0

LVL 74

Expert Comment

ID: 35142250
OK
0

## Featured Post

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
###### Suggested Courses
Course of the Month8 days, 23 hours left to enroll