| Author |
Topic |
|
TheOxblood
Starting Member
19 Posts |
Posted - 2011-09-20 : 10:27:39
|
| Hotel Reservation SystemHow to delete Automatically one or more records based from my computer's time?For example : RoomNumber : 10ReservedTime : 10:00am - 4:00pmWhen my computer's time reached at 4:00pm, RoomNumber 10 will not be Reserved anymore if no clients came. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-20 : 10:46:53
|
| thats just a matter of simple update script. i dont think this needs to be deleted physically. rather it should be logical deletion or update which will change status from Occupied to Vacant or similar values. this updation should happen when customer does check out action.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
TheOxblood
Starting Member
19 Posts |
Posted - 2011-09-20 : 11:24:09
|
| Yes it will does when the client checks out, but then.. i want to it to be deleted when the client did'nt came to check in by that time.Vonn Liquiran |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-20 : 11:31:46
|
| why deleted? what if you want to check previous status of room at later stage? or is there separate history/audit table?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
TheOxblood
Starting Member
19 Posts |
Posted - 2011-09-20 : 11:57:31
|
| Im sorry, I want to update the RoomStatus automatically not delete :)Vonn Liquiran |
 |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2011-09-20 : 12:05:41
|
Hello Vonn ,If your table structure is given here; http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=165638 - Then you can use similar logic as posted there;UPDATE ReservationSET [status] = <your new status>WHERE GETDATE() >= dateadd(hh,hoursSpan,dateadd(mi, datepart(mi,arrivalTime), dateadd(hh,datepart(hh,arrivalTime),arrivalDate))) We compare the current datetime [GETDATE()] to the calculated departure datetime. If the current datetime >= that datetime then the status will be updated.You can see in the few threads you have here, that we are often performing calculations on the two fields (ArrivalTime and HoursSpan). We are constantly reassembling these to perform compares. If you are in an A&D phase of this system (as you suggested), if might be worth it to consider storing the values as native datetime rather than seperating them into a date and then a time. So you end up with columns which are native (i.e. ArrivalDateTime and DepartureDateTime). Storing these as native datetime values will reduce coding, improve filtering, and improve query execution by making filters sargable. Some options would be to format the date and time in the client application before they are persisted to the DB native datetime datatypes, you could create computed columns in Reservation table, or you could use a UDF to replace the continual date functions to reassemble date and time. Here is a simple udf to perform the conversion;CREATE FUNCTION dbo.udfConvertDateTime (@Date smalldatetime, @Time smalldatetime, @Hours tinyint)RETURNS smalldatetimeASBEGIN DECLARE @result smalldatetime SELECT @result = dateadd(hh,@Hours,dateadd(mi, datepart(mi,@Time), dateadd(hh,datepart(hh,@Time),@Date))) RETURN (@result)ENDGOSELECT dbo.udfConvertDateTime('09-20-11','10:00am',0) AS ArrivalDateTime, dbo.udfConvertDateTime('09-20-11','10:00am',6) AS DepartureDateTimeDROP FUNCTION dbo.udfConvertDateTime Just some thoughts for your consideration.HTH. |
 |
|
|
TheOxblood
Starting Member
19 Posts |
Posted - 2011-09-21 : 01:52:30
|
| I dont get the last part of your answer? You said that "If the current datetime >= that datetime then the status will be updated."That is what I'm thinking, How can I do that? I mean automatically be changed when the dateSpan is already finished.I am using VB 2010 and SQL Server 2008.Vonn Liquiran |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-21 : 05:51:05
|
| why not do this as a part of checkout action?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
TheOxblood
Starting Member
19 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-21 : 07:09:27
|
Something likeSELECT rt.*FROM [ROOM TABLE] rtLEFT JOIN [RESERVATION TABLE] rstON rst.RoomNo = rt.RoomNoAND rst.DepartureDate < GETDATE()WHERE rst.roomNo IS NULL ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
TheOxblood
Starting Member
19 Posts |
Posted - 2011-09-21 : 07:37:05
|
| What do you mean by rt and rst?Vonn Liquiran |
 |
|
|
TheOxblood
Starting Member
19 Posts |
Posted - 2011-09-21 : 08:24:36
|
| I guess I figured it out! Whew! SELECT Booking.BookingID, Booking.ReservationNo, Booking.RoomNo, RoomStatus.RoomStatus, Booking.ArrivalDate, Booking.DepartureDateFROM Booking INNER JOIN RoomStatus ON Booking.RoomStatusId = RoomStatus.RoomStatusIdWHERE (ArrivalDate NOT BETWEEN '06:00:00' AND '12:00:00') OR (DepartureDate NOT BETWEEN '06:00:00' AND '12:00:00')If that query returns nothing, then I can place a reservation for a certain RoomNo :)Thanks for your ideas! :)Vonn Liquiran |
 |
|
|
|