请查看表结构、查询和结果。
会议室
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
预订表
ReservationID RoomID DateTimeStart DateTimeEnd
------------- ----------- ----------------------- -----------------------
1 1 2013-10-10 17:00:00.000 2013-10-10 19:00:00.000
询问
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)
此查询仅返回一条记录,因为它应该返回 4 条记录