Here's what I have:
SELECT Count(*) AS cnt
FROM tblOccurrence AS x
WHERE (((x.OccurrenceDate) Between DateAdd('m',-6,Date()) And Date())
AND ((Exists ( SELECT *
FROM tblOccurrence AS y
WHERE y.TechID = x.TechID AND DATEADD ('d', -1, x.[OccurrenceDate]) = y.[OccurrenceDate]))=False)
AND ((x.TechID)= " & Me.tbxTechID.Text & "))
GROUP BY x.TechID;
This is used to calculate "occurrences" for employee absences, if the employee is unexcused for 1 day it's 1 occurrence. If they are unexcused for 5 days in a row, it's still one occurrence.
This is working perfectly until it was pointed out that if an employee has a M-F shift and calls in on Friday and then on Monday, that is only 1 occurrence. To make things even more tough, our employee shifts very greatly (M-F, Tue-Sat, Sun-Mon, M-Tue & Fri-Sat, etc) ... so I have built a table that holds all the different shifts (about 8 of them) that has 9 columns:
ID - ShiftName - Sunday - Monday - Tuesday - Wednesday - Thursday - Friday - Saturday
The ShiftName is a text field with short descriptions (Mon-Fri, Tue-Fri, Sun-Thu, etc) and then Yes/No fields for the days of the week. Then a check mark is a scheduled day.
So I would love everyone's input for 2 things,
- is this a 'good' way to capture what I need captured?
- how would that SQL statement change to get the occurrence count correct taking into account the unexcused absences that wrap a weekend but count as 1 occurrence?