473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Room availability

My problem is trying to calcuate whether a room is booked during a date
period.

I have a table with two columns (Start and End date).

I need some SQL code to calculate whether a room is booked during a date
range.

e.g.

The booking entry is:

Start
21/11/2005

End
25/11/2005

Any help on this would be appreciated.

The End Date indicates the last night of the stay.

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #1
5 2815
This is a good one. Please poke some holes in what I came up with.

How about this though?? Let me know how you make out. The two dates I
am "plugging" would be the beginning and ending date of the period.

create table room (
RoomNumber varchar(5),
StartDate datetime,
EndDate datetime
)

insert into room values('123','2005-10-04','2005-10-05')
insert into room values('123','2005-10-06','2005-10-07')
insert into room values('123','2005-10-09','2005-10-10')

select distinct roomnumber
from room r1
where startdate not between '2005-10-08' and '2005-10-09'
and enddate not between '2005-10-08' and '2005-10-09'
and not exists(select * from room r2
where r2.roomnumber = r1.roomnumber
and startdate between '2005-10-08' and
'2005-10-09'
and enddate between '2005-10-08' and '2005-10-09')

---
Mark Graveline
Take The Challenge
http://www.sqlchallenge.com
---

Nov 23 '05 #2
This problem has been driving me crazy lol
I run some tests on your code last night and it seems to work.

I am gonna give it a bit more testing tomorrow and adapt the code to
work with multiple rooms, so I will keep you posted.

Thanks for this help :)

Regards,

Steven

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #3
Hi,
what if you add a new column
alter table room
add RoomAvailable char(1)
where value is either 'Y' = room available
or 'N' = room not available

Regards

ActiveCrypt
----------------------------------------------
http://www.activecrypt.com

Nov 23 '05 #4
Hi,

Still having a problem.

I need to use two tables, one for Rooms and one for the actual Booking.
How could I modify this code to work with the two tables AND return me
ALL the rooms which are available.

At the moment, I can only return any rooms which have been previously
booked.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 23 '05 #5
CREATE TABLE Rooms
(room_nbr INTEGER NOT NULL PRIMARY KEY,
bed_size CHAR(1) NOT NULL
CHECK (bed_size IN ('K', 'Q', 'T', 'D')),
..);

CREATE TABLE Bookings
(room_nbr INTEGER NOT NULL
REFERENCES Rooms(room_nbr)
start_date DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
end_date DATETIME, -- null mean occupied,
..);
return me ALL the rooms which are available. <<


SELECT room_nbr
FROM Rooms
WHERE room_nbr
NOT IN (SELECT rom_nbr
FROM Bookings
WHERE @my_date BETWEEN start_date
AND COALESCE (end_date, CURRENT_TIMESTAMP);

Now create a calendar table for other things and get a copy of DSQL FOR
SMARTIES which has a whole section on this knd of query

Nov 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dave Robinson | last post by:
I was wondering if anyone could help me with a problem I'm having. I've been using Dreamweaver to create a hotel booking system for a friend of mine, using MySQL (version 4.0.21) and PHP 5. The...
0
by: Joan MacEachern | last post by:
Date: Thursday, October 2, 2003 Time: 10-11am PT/ 1-2pm ET Some business applications define mission critical. You just can't afford to have them go down. Ever. Is 'always on' a realistic...
0
by: Joan MacEachern | last post by:
This paper presents an availability analysis for multitier, Java(tm) and Web-based application deployments running on the Sun(tm) ONE Application Server 7, Enterprise Edition software. The...
9
by: Dan Williams | last post by:
Can anyone tell me how to go about creating my own custom ASP page that can show several different peoples availability from their Outlook/Exchange 2000 calendars? I don't want to have to ask...
2
by: Andy | last post by:
Hi folks I teach. At school, four IT rooms are booked using a paper based outline timetable. Completing it is easy but basic and impossible to ensure completion of all fields (name, year...
4
by: John Coen | last post by:
Help, does anyone have a database I could use to record downtime on multiple systems, that will also show me availability percentages on a day to day basis worked against actual service hours. If...
4
by: Jeremy | last post by:
How can I prove uptime (or quantify downtime) on an ASP.NET 1.1 Web application (running on an IIS6 Windows Server Standard server)? What's going on here is that I'm considering the feasability...
1
by: ALIABBAS J PETIWALA | last post by:
N -ROOM LIGHTS PROBLEM ======================== THERE IS A BIG SQURE ROOM OF SIDE N WHICH CONSISTS OF N X N SMALLER SQUARE ROOMS(ARRANGED LIKE CHESS BOARD) EACH ROOM HAS A LIGHT. WHEN the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.