patrussell
Technical User
I have a query that is supposed to pull all employees that have clocked in for the past 16 hours but have not clocked out. We are using this for a head count should and emergency occur. The problem I am having is that with the query below I search on the clock in time and look for a null in the clock out time. This works great unless the employee double swiped their time card. In that intance I get two clock in times a few seconds apart but only the latest in time will get the clock out time later. This leaves an active clock in time with a null clock out for an employee that is not on site. Obviously this is bad for what we want to do with this query.
Here is the query
And the results set from that query.
laborcode name (No column name) finishdate
47077 Person 1 4/8/2010 22:32:50 NULL
47077 Person 1 4/8/2010 22:32:54 4/9/2010 8:18:07
46843 Person 2 4/9/2010 6:56:47 NULL
46894 Person 3 4/9/2010 7:22:10 NULL
46805 Person 4 4/8/2010 23:13:42 NULL
47025 Person 5 4/9/2010 7:10:12 NULL
46938 Person 6 4/8/2010 22:56:05 4/9/2010 7:30:35
46938 Person 6 4/8/2010 18:54:13 4/8/2010 19:24:03
46952 Person 7 4/9/2010 3:19:48 NULL
46789 Person 8 4/8/2010 18:40:14 NULL
46789 Person 8 4/8/2010 18:40:17 4/9/2010 3:30:18
The records in bold are examples of the "false" result.
Any help in resolving this is greatly appreciated.
Pat Russell
Here is the query
Code:
SELECT DISTINCT attendance.laborcode,
labor.name,
MAX(attendance.startdate),
attendance.finishdate
FROM [db1].maximo3.dbo.attendance AS attendance
INNER JOIN
[db1].maximo3.dbo.labor AS labor
ON attendance.laborcode = labor.laborcode
WHERE (attendance.startdate >= DATEADD(hh, - 16, CURRENT_TIMESTAMP))
AND (labor.la2 = 'lou')
GROUP BY attendance.laborcode, labor.name,attendance.finishdate
ORDER BY labor.name
And the results set from that query.
laborcode name (No column name) finishdate
47077 Person 1 4/8/2010 22:32:50 NULL
47077 Person 1 4/8/2010 22:32:54 4/9/2010 8:18:07
46843 Person 2 4/9/2010 6:56:47 NULL
46894 Person 3 4/9/2010 7:22:10 NULL
46805 Person 4 4/8/2010 23:13:42 NULL
47025 Person 5 4/9/2010 7:10:12 NULL
46938 Person 6 4/8/2010 22:56:05 4/9/2010 7:30:35
46938 Person 6 4/8/2010 18:54:13 4/8/2010 19:24:03
46952 Person 7 4/9/2010 3:19:48 NULL
46789 Person 8 4/8/2010 18:40:14 NULL
46789 Person 8 4/8/2010 18:40:17 4/9/2010 3:30:18
The records in bold are examples of the "false" result.
Any help in resolving this is greatly appreciated.
Pat Russell