我有下面给出名称的表格
1)tblCarName
2)tblVehicle
3)tblModel
4)tblVehicleAvailability
上面三个表我已经获取了未预订车辆和特定型号的结果,然后是在特定日期车辆可用或不可用的另一条件车辆可用条件。
但我得到的结果是哪辆车不可用。(意味着那些在 tblVehicleAvailability 表中的汽车)但我想要那些不在 tblVehicleAvailability 表中的汽车)
我的查询
select
A.id,
C.vsCarName+' ('+ A.EngineNum+' )' as vsCarName
from tblCarName C
join tblVehicle A on C.id = A.CarId
inner join tblModel B on A.ModelId = B.id
--join tblVehicleAvailability VA on VA.CarId = A.id
WHERE A.id not in
(
SELECT
VehicleId
FROM
tblBooking
WHERE
A.ActiveInactive = 1
AND
Convert(datetime,'2013-09-19 00:00:00.000') --start date
BETWEEN FromDateWithStartTime AND ToDateWithEndTime
OR
Convert(datetime,'2013-09-20 00:00:00.000') --endDate
BETWEEN FromDateWithStartTime AND ToDateWithEndTime
OR
FromDateWithStartTime
BETWEEN Convert(datetime,'2013-09-19 00:00:00.000') --startdate
AND Convert(datetime,'2013-09-20 00:00:00.000') --enddate
OR
ToDateWithEndTime
BETWEEN Convert(datetime,'2013-09-19 00:00:00.000')--start date
AND Convert(datetime,'2013-09-20 00:00:00.000')--enddate
)
AND
A.ModelId='3'
AND
Convert(datetime,'2013-09-19 00:00:00.000') --start date
BETWEEN VA.leaveDate AND VA.leaveToDate
OR
Convert(datetime,'2013-09-20 00:00:00.000') --endDate
BETWEEN VA.leaveDate AND VA.leaveToDate
OR
VA.leaveDate
BETWEEN Convert(datetime,'2013-09-19 00:00:00.000') --startdate
AND Convert(datetime,'2013-09-20 00:00:00.000') --enddate
OR
VA.leaveToDate
BETWEEN Convert(datetime,'2013-09-19 00:00:00.000') --start date
AND Convert(datetime,'2013-09-20 00:00:00.000')