I am creating a room booking system.
I need to create a SQL query so that once a user has selected a date, a list of rooms that have are available on a specific day for a specific time are displayed. But I only store the rooms that are booked.
The 3 tables included in this at the moment are Tbl_Room
, Tbl_Booking
and Tbl_TimeSlot
Tbl_Room
stores all the different rooms.
Tbl_Booking
stores the date booked, RoomID, TimeslotID, BookingName
Tbl_TimeSlot
contains StartTime and EndTime
So, I want to display each time slot that is available for a selected day and a selected time. The SQL query I have tried is:
SELECT
Tbl_TimeSlot.TimeslotID_PK,
Tbl_TimeSlot.StartTime,
Tbl_TimeSlot.EndTime,
Tbl_Booking.RoomID_FK,
Tbl_Booking.BookingName,
Tbl_Booking.BookingDate,
Tbl_Room.RoomName
FROM
Tbl_Room RIGHT
OUTER JOIN
Tbl_Booking ON Tbl_Room.RoomID_PK = Tbl_Booking.RoomID_FK
RIGHT OUTER JOIN
Tbl_TimeSlot ON Tbl_Booking.TimeSlotID_FK = Tbl_TimeSlot.TimeslotID_PK
WHERE (Tbl_Booking.BookingDate <> @BookingDate)
AND (Tbl_Booking.RoomID_FK <> @RoomID)
But nothing is appearing.
Any suggestions?