erikTsomik
asked on
sql check if the datetime in between 2 datetime
I have a query and What I trying to do is to exclude the people that are taken in this time frame, but it still showing me a person where this person should be excluded
SELECT DISTINCT U.userKey
, U.firstName
, U.lastName
, U.email
FROM users U
WHERE U.enable = 'Y' and u.userKey=36749
and not EXISTS (
SELECT su.instructorKey
FROM Session S
INNER JOIN SessionUnit SU ON S.SessionKey = SU.SessionKey
inner join sessionMap SM on SM.sessionKey= S.sessionKey
WHERE
su.instructorKey = U.userKey
AND
(
'2015-09-01 08:01:00' between SU.sessionStart and SU.sessionEnd
OR '2015-09-01 09:59:00' between SU.sessionStart and SU.sessionEnd
OR SU.sessionStart between '2015-09-01 08:01:00' AND '2015-09-01 09:59:00'
OR SU.sessionEnd between '2015-09-01 08:01:00' AND '2015-09-01 09:59:00'
)
)
order by U.lastName
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
AND SU.sessionStart < '2015-09-01 10:10:00'
AND SU.sessionEnd > '2015-09-01 08:00:00'
nothing else is needed