Here, we have many meetings during the day. Usually from 9:00am-11:30am, 1:00pm-3:30pm, 4:00pm-6:30pm.
I'm having a hard time scheduling these meetings. I don't get how to check if they overlap for the same person who is leading the meeting.
Ex: Should raise an error if Person1 has a meeting scheduled for 10:00am- 11:00am and another for 10:45am-11:30am.
I've come to this solution, but it is only partially working:
if exists (
select 1
from
Meeting M
where
M.IdPerson = @IdPerson --Stored procedure parameter
and
(@StartDate <= M.EndDate or -- 1
@EndDate >= M.StartDate or -- 2
(@StartDate > M.StartDate and @DtFim < A.Data_Termino))) -- 3
return 1
In the image below, I explain the three conditions in the where clause. The green lines are the new meeting start and end dates. The red lines are the old's.
How can I make this work?