thumper808
Technical User
Hi everyone,
I've been racking my brains for days on my problem. I have a table called ROOMBOOKINGS and some of it's fields are RoomNumber, BookingStartDate and BookingEndDate. The RoomNumber is a foreign key to the ROOMS table which has the RoomNumber,Description,and RoomRate.
All I want to do is select all the rooms which are available to book.
So what I did was this:
create procedure FindRoomAvailabilitybyDate (@StartDate datetime, @EndDate datetime)
as
select * from rooms
where not roomnumber in
(select roombookings.roomnumber from roombookings
where bookingstartdate between @StartDate and @EndDate)
but this only gives me the rooms available if I enter exact dates.
For example, if an existing booking is for 11/1/2002 to 11/6/2002, and I enter those dates respectively, the procedure works like a charm. BUT if I enter a starting date of 11/2/2002 and 11/5/2002 for an ending date into the SP, it doesn't work. Please forgive my long winded explanation but I'm kinda new to sql and I did look on the existing threads before I wrote to you all.
I guess I want to know how to do the 'catch all' for a problem like this.
Thank you very much in advance.
Thumper (-:
I've been racking my brains for days on my problem. I have a table called ROOMBOOKINGS and some of it's fields are RoomNumber, BookingStartDate and BookingEndDate. The RoomNumber is a foreign key to the ROOMS table which has the RoomNumber,Description,and RoomRate.
All I want to do is select all the rooms which are available to book.
So what I did was this:
create procedure FindRoomAvailabilitybyDate (@StartDate datetime, @EndDate datetime)
as
select * from rooms
where not roomnumber in
(select roombookings.roomnumber from roombookings
where bookingstartdate between @StartDate and @EndDate)
but this only gives me the rooms available if I enter exact dates.
For example, if an existing booking is for 11/1/2002 to 11/6/2002, and I enter those dates respectively, the procedure works like a charm. BUT if I enter a starting date of 11/2/2002 and 11/5/2002 for an ending date into the SP, it doesn't work. Please forgive my long winded explanation but I'm kinda new to sql and I did look on the existing threads before I wrote to you all.
I guess I want to know how to do the 'catch all' for a problem like this.
Thank you very much in advance.
Thumper (-: