473,492 Members | 4,279 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with displaying information not booked on a certain date.

9 New Member
Hi,

I am doing an online booking project and was wondering if anyone has any ideas on how I can display rooms that are not booked on a certain date. The query that I have that displays all rooms that are not booked is:

SELECT rooms.roomid, rooms.rtype
FROM rooms
LEFT JOIN reservation
ON rooms.roomid = reservation.roomid
WHERE rooms.hostelid = 6
AND (((reservation.roomid) Is Null));

But I want to edit this to show all rooms that are not booked on a certain date say 05-JAN-07. I have tried the following query to try make this work:

SELECT rooms.roomid, rooms.rtype
FROM rooms
LEFT JOIN reservation
ON rooms.roomid = reservation.roomid
WHERE rooms.hostelid = 6
AND (((reservation.roomid) Is Null) and ((reservation.fromdate) !='05-JAN-07')));

Any advice on where I am goin wrong would be great!

thanks
Jan 9 '07 #1
9 1801
iburyak
1,017 Recognized Expert Top Contributor
Try to remove this line :

AND (((reservation.roomid) Is Null)
Jan 9 '07 #2
simba
9 New Member
No that doesn't work because it just returns reservations that have been made rather than available rooms.

Thanks though!
Jan 9 '07 #3
iburyak
1,017 Recognized Expert Top Contributor
Change to >= instead of !=

((reservation.fromdate) >='05-JAN-07')));
Jan 9 '07 #4
simba
9 New Member
That doesn't work either sorry. My reservation table contains bookings that have been made but i'm trying to search for rooms that are available and not on the dates that the rooms are booked up on.
Jan 9 '07 #5
iburyak
1,017 Recognized Expert Top Contributor
You probably need a third table that has all dates in a calendar and join to that table to find available once.
Jan 9 '07 #6
almaz
168 Recognized Expert New Member
You probably need a third table that has all dates in a calendar and join to that table to find available once.
Not at all. There is a much simpler way (by the way, it is suggested to use parametrized queries, and also the most correct way of setting datetime value is to use 8-digit string as I show in my sample):
Expand|Select|Wrap|Line Numbers
  1. DECLARE @hostelid int 
  2. DECLARE @fromdate datetime 
  3. DECLARE @todate datetime 
  4.  
  5. SET @hostelid = 6
  6. SET @fromdate = '20070105'
  7. SET @todate = '20070110'
  8.  
  9. SELECT rooms.roomid, rooms.rtype
  10. FROM rooms
  11. WHERE rooms.hostelid = @hostelid
  12.     AND rooms.roomid NOT IN 
  13.     (
  14.         SELECT reservation.roomid
  15.         FROM reservation
  16.         WHERE reservation.fromdate < @fromdate and reservation.todate > @todate
  17.     )
Jan 10 '07 #7
simba
9 New Member
Thats excellent, worked a treat! thanks! I have one other wee question...I dont suppose you have any idea how to automatically delete an entry from a table once its todate has expired i.e. the date on which people will be checking out of their hotel?

Thanks again!
Jan 10 '07 #8
almaz
168 Recognized Expert New Member
Do you mean expired reservations? I would leave them just to be able to see the reservation history (and, create reports to see reservation trends), but if you want to remove old records - you can set up an SQL job that will run every midnight and perform database maintenance like deleting or archiving old records.
Jan 10 '07 #9
simba
9 New Member
Yeah I mean reservations. Your completely right tho I dont know what I was thinking wanting to delete them! My head was all confused and I was thinking that I had to delete them so that they didnt mess with my query that shows the availability of rooms on certain dates but it will make no difference because once the check out date has passed it will be in-line with the real date i.e. todays date, which people cannot book prior to todays date anyway!

Thanks again for the help!
Jan 10 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1431
by: Eva | last post by:
Hi, Im new to Vb.net and am trying to create my first practice project. The problem iv encountered is to do with SQL queries issued against my Access DB iv created. i want to wright a query...
15
5730
by: plaztik8 | last post by:
Hello, Can someone please help me with a query? The table looks like this: BookedRooms =========== CustomerID RoomID BookDateID
8
5448
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
18
12779
by: Jeremy Weiss | last post by:
I'm trying to build a database that will handle the monthly billing needs of a small company. I'm charting everything out and here's what I see: table for customers sub table to track payments...
2
3129
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
6
1724
by: shaunb | last post by:
Hi, just new to this forum, and i was wondering if anyone could help me. I've got a piece of work to do, i have done the majority of it, just the last, and the most important thing lol, that i am...
2
1053
by: snk | last post by:
hello, Iam new in MySQL, in fact its my first day but i have stacked for several hours. I have 3 subqueries, i can mix the 2 of them but i get an error for the third one the first one is ...
3
2380
by: Lester | last post by:
I'm driving myself crazy with a problem in trying to translate a query written for Access to that for SQL server. I would think that I would use a trigger, but am not sure how to set it up. We...
7
2279
by: William (Tamarside) | last post by:
Please, if you have the time and knowledge to help me I'd truly appreciate it! I need to build a calendar page that displays available/unavailable info from a DB and colour a cell according to...
0
7118
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
6980
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
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7192
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...
1
6862
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
7364
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...
1
4886
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3087
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.