Kindly see the Table Structure , Query and the Result.
MeetingRoom
ID | Area | RoomNo Capacity distances
--- ----- --------- ---------- ----------
1 1 R1 10 10
2 1 R3 24 4
3 8 R4 24 4
4 1 R5 10 10
ReservationTable
ReservationID RoomID DateTimeStart DateTimeEnd
------------- ----------- ----------------------- -----------------------
1 1 2013-10-10 17:00:00.000 2013-10-10 19:00:00.000
Query
Declare @Start Datetime
Declare @End Datetime
set @Start='2013-10-10 13:00:00.000'
set @End='2013-10-10 14:00:00.000'
select
MeetingRoom.ID
from
MeetingRoom
left Join ResReservationTable Res on Res.RoomID = MeetingRoom.ID
Where
Res.DateTimeStart != @Start and Res.DateTimeEnd != @End
and (Res.DateTimeStart Not Between @Start and @End)
and (Res.DateTimeEnd Not Between @Start and @End)
This Query is Returning only one record as it should return 4 Records
If you use
LEFT OUTER JOINand inWHERE clauseset condition to right-hand table rather thanIS NULLin result you haveINNER JOIN.I think this is what you want.
I think you must rephrase your
WHEREcondition. If you want room which fully free (i.e. intervals not intersect) you can use this: