Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5940119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:55:26+00:00 2026-05-22T15:55:26+00:00

I’m using Microsoft’s idea for storing resource and booking information. In short, resources, such

  • 0

I’m using Microsoft’s idea for storing resource and booking information. In short, resources, such as a hotel room, do not have date records and booking records have a BeginDate and EndDate.

I’m trying to retrieve room availability information using MS’s queries but something tells me that MS’s queries leave much to be desired. Here’s the MS article I’m referring to: http://support.microsoft.com/kb/245074

How can I retrieve available rooms for a given date range? Here’s my query that returns a simple list of bookings:

SELECT r.RoomID, b.BeginDate, b.EndDate
FROM tblRoom as r INNER JOIN tblBooking b ON r.RoomID = b.AssignedRoomID;

But I’m still baffled as to how I can get a list of available rooms for a given date range?

I am using Microsoft Access but I’d like to keep my queries DBMS agnostic, as much as possible. While this isn’t really my question, if you feel that the data model I’m using is unsound, please say so, as I am willing to consider a better way of storing my data.

Edit1:
I failed to mention that I don’t like MS’s queries for two reasons. First of all, I’m really confused about the 3 different OR operators in the WHERE clause. Are those really necessary? Secondly, I don’t like the idea of saving a query and using it as a table although I’m willing to do that if it gets the job done, which in this case I believe it does.

Edit2:
This is the solution I’ve landed on using the excellent answer given here. This is MS Access SQL dialect (forgive me):

SELECT * FROM tblRoom AS r  
WHERE RoomID NOT IN  
 (SELECT AssignedRoomID as RoomID From tblBooking  
  WHERE assignedroomid IS NOT NULL AND assignedroomid = r.roomid AND 
    (BeginDate < @BookingInquiryEndDate AND EndDate > @BookingInquiryBeginDate)  
 )
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:55:27+00:00Added an answer on May 22, 2026 at 3:55 pm

    You want all the rooms which do not have a booking in that date range, i.e.,
    If your sql engine does subqueries…

    Select * From Rooms r 
    where not exists 
         (Select * From Bookings 
          Where room = r.room
             And startBooking < @endRange
             And endBooking > @startRange)
    

    HIK, to understand the need for the room = r.room clause try these two queries

    Query One (with room = r.room clause)

           Select r.*,
           Case Where Exists
               (Select * From Bookings 
                Where room = r.room
                     And startBooking < @endRange
                     And endBooking > @startRange) 
            Then 'Y' Else 'N' End HasBooking
        From Rooms r 
    

    Query Two(without room = r.room clause)

        Select r.*,
           Case Where Exists
               (Select * From Bookings 
                Where startBooking < @endRange
                     And endBooking > @startRange) 
            Then 'Y' Else 'N' End HasBooking
        From Rooms r 
    

    Notice the first one returns different values in HasBooking for each row of the output, because the subquery is ‘Correleated’ with the outer query… it is run over and over agaio, once for each outer query results row.

    The second one is the same value for all rows… It is only executed once, because nothing in it is dependant on which row of the outer query it is being generated for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.