I've been working on a similar attendance project myself and like Mike I've
been trying to distinguish between the number of days missed and number of
violations where one violation can = multiple days. So a new record is
created in the violations table for every day missed. Every record has a
unique violation id (counts the days missed) and has a non-unique violation
id to (hopefully) count the number of violations.
ViolationIDAdv, Date, ViolationUniqueID
1, 1/2/08, 1
1, 1/3/08, 2
1, 1/6/08, 3
2, 2/5/08, 4
Here's the query I have (this also has multiple sub-queries that count:
Tardies, Partial Days worked, No-Shows, etc).
SELECT e.EmpFullName AS [Full Name],
(Select count(distinct v.violationidadv) from Tbl_Violations v where
(v.DateofOccurance>DateAdd("m",-12,Date())) and v.typeid = 1 and v.excusable
= no and v.employeeid = e.employeeid) AS Violations,
(Select count(v.violationuniqueid) from Tbl_Violations v where
(v.DateofOccurance>DateAdd("m",-12,Date())) and v.typeid = 1 and v.excusable
= no and v.employeeid = e.employeeid) AS Days,
(Select count(v.violationuniqueid) from Tbl_Violations v where
(v.DateofOccurance>DateAdd("m",-12,Date())) and v.typeid = 7 and v.employeeid
= e.employeeid) AS [No Call/No Show],
(Select count(v.violationuniqueid) from Tbl_Violations v where
(v.DateofOccurance>DateAdd("m",-12,Date())) and v.typeid = 2 and v.employeeid
= e.employeeid) AS Tardies,
(Select count(v.violationuniqueid) from Tbl_Violations v where
(v.DateofOccurance>DateAdd("m",-12,Date())) and v.typeid = 6 and v.employeeid
= e.employeeid) AS [Partial Days],
(Select v.dateofoccurance from Tbl_Violations v where
(v.DateofOccurance>DateAdd("m",-12,Date())) and v.typeid = 5 and v.employeeid
= e.employeeid) AS [Final Warning],
Tbl_Supervisors.SupervisorName
FROM Tbl_Employees AS e
INNER JOIN Tbl_Supervisors ON e.SupervisorID=Tbl_Supervisors.SupervisorID
WHERE (((e.Inactive)=False) AND ((e.PositionID)<>5))
ORDER BY Tbl_Supervisors.SupervisorName, e.EmpFullName;
As soon as I added "Disctinct" in the first subquery count, Access returns a
syntax error. Any ideas how I can revise the first subquery to count only
the number of unique non-unique id's?
Dex
:
James... Your wonderful. I can't thank you enough.
Mike.
: