SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Check room availability in hotel system


Check room availability in hotel system

Author
Message
mfundotogu
mfundotogu
Valued Member
Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)

Group: General Forum Members
Points: 51 Visits: 53
[font="Times New Roman"][/font]
I'm a university student and I'm developing a database for a hotel system ,now I'm stack when I try to check rooms that are available for a specific date,room_status and type of a room.I'm using SQL server 2008, I have two table that m checking on which are : dbo.RoomBooking(Booking_ID,Room_Number,Arrival_date,Departure_date) , dbo.Rooms(Room_Number,Room_type,Room_status)

I hv tried this query: create proc GetAvailableRoom
(@RT_Name char(15), @ArriveDate Date, @DepDate Date)
AS SELECT Room_no from Rooms r ,Room_Type rt
WHERE r.Room_Type_Code = rt.Room_Type_Code and
Room_no NOT IN (Select Room_no FROM Room_Bookings
Where Chck_in_Date Between @ArriveDate and @DepDate and
Chck_out_Date between @ArriveDate and @DepDate)
and rt.Room_Type_Name = @RT_Name and Room_Status = 'Avail'
go
Andre Guerreiro
Andre Guerreiro
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2213 Visits: 1515
Nobody's going to help you now that you started spamming the forums.
That smells homework and you could at least have posted DDL and DML code and what you have so far and not try to make people make your homework for you.

Best regards,

Andre Guerreiro Neto

Database Analyst
http://www.softplan.com.br
MCITPx1/MCTSx2/MCSE/MCSA
GilaMonster
GilaMonster
SSC Guru
SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)

Group: General Forum Members
Points: 216881 Visits: 46278
What's the table definitions? What's the sample data? What's the problem with the query?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


mfundotogu
mfundotogu
Valued Member
Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)

Group: General Forum Members
Points: 51 Visits: 53
@
I ddnt knw posting the same post many time is spamming ,I was trying to get help as quick as possible. The project tht I'm doing is industrial not a school work, by writing m a university student,I wanted you to knw tht I dnt have that much stills.
J Livingston SQL
J Livingston SQL
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11805 Visits: 37484
mfundotogu (8/26/2012)
@
I ddnt knw posting the same post many time is spamming ,I was trying to get help as quick as possible. The project tht I'm doing is industrial not a school work, by writing m a university student,I wanted you to knw tht I dnt have that much stills.


this type of question appears on this site quite regularly....try searching the site for "hotel"

as an example

http://www.sqlservercentral.com/Forums/Topic1259572-392-1.aspx

________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day

mfundotogu
mfundotogu
Valued Member
Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)

Group: General Forum Members
Points: 51 Visits: 53
create table Rooms
(Room_no char(4) primary key not null,
Room_Status varchar(20) not null,
Room_Type_Code char(4) foreign key references Room_Type(Room_Type_Code))
go
Data in the Table.
1011 Avail STD1
1012 Avail STD1
2011 Avail DLX2

Create table Room_Bookings
(Booking_ID char(8) NOT NULL ,
Room_no char(4) NOT NULL Foreign KEY REFERENCES Rooms,
Adult_Num int ,
Child_Num int,
Chck_in_Date date,
Chck_out_Date date,
Rack_Rate decimal(7,2),
Guest_ID char(13)
)
go
Booking_ID R_No Arrv_Date Dep_Date
08304412 4012 2012-08-15 2012-08-25 750.00 9210021234567
08374412 4012 2012-08-20 2012-09-28 750.00 9210021234567
0855412 1012 2012-08-15 2012-09-30 450.00 9201112345678
12345678 1012 2012-08-22 2012-08-23 450.00 0987654321123
12345678 1012 2012-08-25 2012-09-23 450.00 0987654321123

The query does nt return correct room_Nos if the Arrv_Date and Dep_date are within the range of booked dates.
e.g Arrv_Date:2012-08-22 ,Dep_date:2012-09-20 ,it will return room 4012 and 1012 ofwhich they are booked by tht date.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)

Group: General Forum Members
Points: 216881 Visits: 46278
So what should it return?
http://www.sqlservercentral.com/articles/Best+Practices/61537/

p.s. Hotel booking systems are often used as exercises for database courses because they're very hard to get right.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


mfundotogu
mfundotogu
Valued Member
Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)

Group: General Forum Members
Points: 51 Visits: 53
It must return rooms that are not booked at those dates.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)SSC Guru (216K reputation)

Group: General Forum Members
Points: 216881 Visits: 46278
And those are? Be specific, list exactly what must be returned (as the article I linked explains)

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


mfundotogu
mfundotogu
Valued Member
Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)

Group: General Forum Members
Points: 51 Visits: 53
Booking_ID R_No........... Arrv_Date .............Dep_Date
08304412 4014........... 2012-08-15 ..........2012-08-25 750.00 9210021234567
08374412 4011........... .....2012-08-20 ..........2012-09-28 750.00 9210021234567
0855412 2013..................2012-08-15......... 2012-09-30 450.00 9201112345678
12345678 3014 ................2012-08-22 ..........2012-08-29 450.00 0987654321123
12345678 1015 ................2012-08-20..........2012-09-23 450.00 0987654321123

Arrival Date :2012-08-30 Departure date 2012-09-10
It should return Room_No: 4014......2012-08-15....2012-08-25
------------------------- 3014......2012-08-22.....2012-08-29

but it also return Room_No: 2013.....2012-08-15.....2012-09-30
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search