0

I'm trying to do a query to discover which days an employee didn't work.

For example:

If I retrieve all the dates between 21/07 and 25/07 that the employee worked I will have something like that:

21/07/2016
22/07/2016
23/07/2016
25/07/2016

But I want the days that he didn't work. In this case it's 24/07.

I'm looking for a solution and my idea is to do a subquery retrieving an interval of dates, but as rows to do a not contains on the query above.

Example:

SELECT MyDate 
FROM MyTable
WHERE MyDate between 21-07 and 25-05
and MyDate not in 
**(the subquery here)**

Anyone can help?

DavidG
  • 113,891
  • 12
  • 217
  • 223
Ricardo França
  • 2,923
  • 2
  • 18
  • 18

1 Answers1

-2

Best way is with not exists and you need to query a table that has all the possible date values:

SELECT ALLDATECOLUMN FROM ALLDATES
WHERE 
NOT EXISTS (SELECT 1 FROM MYDATES WHERE MYDATES = ALLDATECOLUMN)
AND ALLDATECOLUMN BETWEEN 21-07 AND 25-05
Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116
TimW
  • 1