You need to move the HAVING clause to a WHERE clause and also search for
nulls since you are looking at the Many table. Try this modification to
your SQL.
SELECT tblDepartment.Department, tblAllWorkLoggedRecords.Date,
Count(tblAllWorkLoggedRecords.ID) AS CountOfID
FROM tblDepartment LEFT JOIN tblAllWorkLoggedRecords ON
tblDepartment.Department = tblAllWorkLoggedRecords.DEPARTMENT
WHERE tblAllWorkLoggedRecords.Date=[enter date]
OR tblAllWorkLoggedRecords.Date Is Null
GROUP BY tblDepartment.Department, tblAllWorkLoggedRecords.Date
IF you switch back to the design view (grid view), you will see
tblAllWorkLoggedRecords.Date in the list of field twice. Once with the
Total line set as GROUP BY and once with the Total line set as WHERE.
WHERE filters the records BEFORE the Totals are calculated. HAVING
filters the results after the totals are calculated.
Usually you are better off using WHERE when you are applying criteria
against a field you are grouping.
WMorsberger said:
Here is the query that I have - I have tried all the joins and it doesn't
seem to be working, but then again maybe I'm missing something. It's
still
not showing me all the departments
SELECT tblDepartment.Department, tblAllWorkLoggedRecords.Date,
Count(tblAllWorkLoggedRecords.ID) AS CountOfID
FROM tblDepartment LEFT JOIN tblAllWorkLoggedRecords ON
tblDepartment.Department = tblAllWorkLoggedRecords.DEPARTMENT
GROUP BY tblDepartment.Department, tblAllWorkLoggedRecords.Date
HAVING (((tblAllWorkLoggedRecords.Date)=[enter date]));
:
Do you have a table of Departments? If so include it in your query with
an
outer join. Probably something LIKE the following.
SELECT tblDepartments.Department
, tblAllWorkLoggedRecords.Date
, Count(tblAllWorkLoggedRecords.[REPORT NAME]) AS [CountOfREPORT NAME]
FROM tblDepartments LEFT JOIN tblAllWorkLoggedRecords
ON tblDepartments.Department = tblAllWorkLoggedRecords.Department
WHERE tblAllWorkLoggedRecords.Date Between [Enter Start Date:
mm/dd/yyyy]
And [Enter End Date: mm/dd/yyyy]
OR tblAllWorkLoggedRecords.Date is Null
GROUP BY tblAllWorkLoggedRecords.DEPARTMENT,
tblAllWorkLoggedRecords.Date
I have a report that I am running - Although when run the report I want
it
to
show me the information whether there is a count of zero or not. How
can
I
set this up on my report or my query?
Here is the query that I have my report linked to - Even if the
department
doesn't have a count to show, I still would like it to say zero.
SELECT tblAllWorkLoggedRecords.DEPARTMENT,
tblAllWorkLoggedRecords.Date,
Count(tblAllWorkLoggedRecords.[REPORT NAME]) AS [CountOfREPORT NAME]
FROM tblAllWorkLoggedRecords
GROUP BY tblAllWorkLoggedRecords.DEPARTMENT,
tblAllWorkLoggedRecords.Date
HAVING (((tblAllWorkLoggedRecords.Date) Between [Enter Start Date:
mm/dd/yyyy] And [Enter End Date: mm/dd/yyyy]));