how to check availability

P

pam2004

Hi I am creating a system similar to a car hire system. I need to creat
a query to compare two dates RequiredDate and ReturnDate using te
dattdiff function to enable the query to display all cars/ that are no
already on hire for that period. Please help
 
A

Allen Browne

The cars booked for any part of the period between StartDate and EndDate
are found with:
[RequiredDate] <= [LastDate] And [ReturnDate] >= [StartDate]

You want the other cars:

SELECT * FROM tblCar WHERE NOT EXISTS
(SELECT BookingID FROM tblBooking
WHERE ([RequiredDate] <= [LastDate])
AND ([ReturnDate] >= [StartDate])
AND (tblBooking.CarID = tblCar.CarID) );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top