Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You basically want to select every staff member from your staff table and then exclude anyone who logged in on a particular day. In short, this creates a list of PersonID not seen on a given day.</p> <p>This solution works, complete with example cases:</p> <pre><code>CREATE TABLE #temp (TimeSheetLogId INT IDENTITY(1,1), InTimeStamp DATETIME, OutTimeStamp DATETIME, PersonID INT); -- last week -- PersonID=1, didnt come to work last monday -- INSERT #temp VALUES ('2013-11-19 09:00:00.000','2013-11-19 17:00:00.000',1); INSERT #temp VALUES ('2013-11-20 09:00:00.000','2013-11-20 17:00:00.000',1); INSERT #temp VALUES ('2013-11-21 09:00:00.000','2013-11-21 17:00:00.000',1); INSERT #temp VALUES ('2013-11-22 09:00:00.000','2013-11-22 17:00:00.000',1); INSERT #temp VALUES ('2013-11-23 09:00:00.000','2013-11-23 17:00:00.000',1); -- 9AM-5PM shift INSERT #temp VALUES ('2013-11-19 09:00:00.000','2013-11-19 17:00:00.000',2); INSERT #temp VALUES ('2013-11-20 09:00:00.000','2013-11-20 17:00:00.000',2); INSERT #temp VALUES ('2013-11-21 09:00:00.000','2013-11-21 17:00:00.000',2); INSERT #temp VALUES ('2013-11-22 09:00:00.000','2013-11-22 17:00:00.000',2); INSERT #temp VALUES ('2013-11-23 09:00:00.000','2013-11-23 17:00:00.000',2); -- 11PM-7AM shift INSERT #temp VALUES ('2013-11-18 23:00:00.000','2013-11-19 07:00:00.000',3); INSERT #temp VALUES ('2013-11-19 23:00:00.000','2013-11-20 07:00:00.000',3); INSERT #temp VALUES ('2013-11-20 23:00:00.000','2013-11-21 07:00:00.000',3); INSERT #temp VALUES ('2013-11-21 23:00:00.000','2013-11-22 07:00:00.000',3); INSERT #temp VALUES ('2013-11-22 23:00:00.000','2013-11-23 07:00:00.000',3); -- this week INSERT #temp VALUES ('2013-11-25 09:00:00.000',NULL,1); INSERT #temp VALUES ('2013-11-25 09:00:00.000',NULL,2); INSERT #temp VALUES ('2013-11-24 23:00:00.000',NULL,3); DECLARE @ExamineDate DATE = '2013-11-19' -- You want to select DISTINCT PersonID from your main STAFF table that contains all records, I did this for simplicity! SELECT DISTINCT(PersonID) FROM #temp A EXCEPT -- this query should remain as-is SELECT PersonID FROM #temp A WHERE CAST(A.InTimeStamp AS DATE) = @ExamineDate OR CAST(A.OutTimeStamp AS DATE) = @ExamineDate ; DROP TABLE #temp; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload