Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Check room availability in hotel system Expand / Collapse
Author
Message
Posted Sunday, August 26, 2012 11:24 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, October 3, 2012 1:28 PM
Points: 11, 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
Post #1350128
Posted Sunday, August 26, 2012 11:37 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, September 12, 2014 5:33 AM
Points: 900, Visits: 1,489
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
Post #1350131
Posted Sunday, August 26, 2012 12:13 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 9:33 AM
Points: 43,026, Visits: 36,190
What's the table definitions? What's the sample data? What's the problem with the query?


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
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

Post #1350138
Posted Sunday, August 26, 2012 12:21 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, October 3, 2012 1:28 PM
Points: 11, 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.
Post #1350139
Posted Sunday, August 26, 2012 12:39 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 9:33 AM
Points: 1,920, Visits: 19,357
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
Post #1350141
Posted Sunday, August 26, 2012 12:44 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, October 3, 2012 1:28 PM
Points: 11, 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.


Post #1350142
Posted Sunday, August 26, 2012 12:52 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 9:33 AM
Points: 43,026, Visits: 36,190
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 2008, MVP
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

Post #1350143
Posted Sunday, August 26, 2012 12:59 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, October 3, 2012 1:28 PM
Points: 11, Visits: 53
It must return rooms that are not booked at those dates.
Post #1350146
Posted Sunday, August 26, 2012 1:10 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 9:33 AM
Points: 43,026, Visits: 36,190
And those are? Be specific, list exactly what must be returned (as the article I linked explains)


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
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

Post #1350147
Posted Sunday, August 26, 2012 1:51 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, October 3, 2012 1:28 PM
Points: 11, 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
Post #1350150
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse