>Didn't know how to describe this in the subject, but I need a query that
>counts the number of items in certain categories, but if that category is
[quoted text clipped - 3 lines]
>zero, and I need a listing of all categories regardless of whether they're
>zero (or null), along with how many in each category.
You will need a table that has a record for each possible
category. Then you can use an outer join to the data you
are counting.

Signature
Marsh
MVP [MS Access]
Sandy - 31 Jan 2006 15:16 GMT
Thanks for responding, Barton.
I used the following query:
SELECT tblDeclaration.Declaration, Count(*) AS NumOfDecl
FROM tblDeclaration Left JOIN tblCalls ON tblDeclaration.DeclarationID =
tblCalls.DeclarationID
GROUP BY tblDeclaration.Declaration;
It still isn't returning any rows that are less than 1. Any idea what I'm
doing wrong? Also, I have to manage to use another column from tblCalls -
CallDate, in addition to getting Count, because I need the count of each
Declaration between two dates. [By the way, tblCalls is the Main table.]
What am I doing wrong in the above query?

Signature
Sandy
> >Didn't know how to describe this in the subject, but I need a query that
> >counts the number of items in certain categories, but if that category is
[quoted text clipped - 7 lines]
> category. Then you can use an outer join to the data you
> are counting.
Marshall Barton - 31 Jan 2006 17:02 GMT
>I used the following query:
>
[quoted text clipped - 7 lines]
>CallDate, in addition to getting Count, because I need the count of each
>Declaration between two dates. [By the way, tblCalls is the Main table.]
I think the issue is that you are using Count(*). That will
count all the rows, regardless of their content. Try
changing it to:
. . ., Count(tblCalls.DeclarationID) AS NumOfDecl

Signature
Marsh
MVP [MS Access]
Sandy - 31 Jan 2006 19:28 GMT
Thanks, Marshall!

Signature
Sandy
> >I used the following query:
> >
[quoted text clipped - 12 lines]
> changing it to:
> . . ., Count(tblCalls.DeclarationID) AS NumOfDecl
Sandy - 31 Jan 2006 15:37 GMT
I just tried the following -
SELECT tblDeclaration.Declaration, Count(*) AS NumOfDecl
FROM qryOne RIGHT JOIN tblDeclaration ON qryOne.DeclarationID =
tblDeclaration.DeclarationID
GROUP BY tblDeclaration.Declaration
qryOne is a regular join between tblCalls and tblDeclaration. I ran a query
using tomorrow's date, just to see if it would return 23 rows, all with 0 and
it returned 23 rows, but each with a 1 as the NumOfDecl. [There are no
entries yet for tomorrow.] What could be causing that?

Signature
Sandy
> >Didn't know how to describe this in the subject, but I need a query that
> >counts the number of items in certain categories, but if that category is
[quoted text clipped - 7 lines]
> category. Then you can use an outer join to the data you
> are counting.
John Spencer - 31 Jan 2006 16:18 GMT
Count counts all the non-null values.
Therefore Count(*) will return a count of the total number of aggregated
rows. Since you are forcing a row to be returned, the count will be 1
Try Count(tblDeclaration.DeclarationID) since that value can be null
>I just tried the following -
>
[quoted text clipped - 24 lines]
>> category. Then you can use an outer join to the data you
>> are counting.
Sandy - 31 Jan 2006 19:28 GMT
Thanks, John!

Signature
Sandy
> Count counts all the non-null values.
> Therefore Count(*) will return a count of the total number of aggregated
[quoted text clipped - 30 lines]
> >> category. Then you can use an outer join to the data you
> >> are counting.