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

Open in new window

LVL 19
erikTsomikSystem Architect, CF programmer Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
this is the simple condition:

AND  SU.sessionStart < '2015-09-01 10:10:00'
AND SU.sessionEnd > '2015-09-01 08:00:00'

nothing else is needed
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
Problem are the OR's. You don't need them:
 (SU.sessionStart between '2015-09-01 08:01:00' AND '2015-09-01 09:59:00')
AND (SU.sessionEnd between '2015-09-01 08:01:00' AND '2015-09-01 09:59:00')

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.