Solved

Show 0 when Count is Zero

Posted on 2011-03-14
6
561 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

760 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now