I need help, CFquery and SQL NOT BETWEEN

OK I am building a hotel booking system as a college project and I'm having trouble with finding rooms that are available. Now I have got this working, to an extent, So to give you the bigger picture al try and lay this out the best I can so you can understand.
This is my database structure:
Bookings Table
Rooms Table
Customers Table
BookingID
BookingDateIN
BookingDateOUT
RoomID
CustomerID
RoomID
RoomType
RoomNumber
RoomPrice
Room Description
CustomerID
FullName
AddressLine1
AddressLine2
PostalCode
CarReg
OK, now you can see how this is going to work with the Bookings Tables RoomID and CustomerID matching the others to make a relationship, simple databasing.
Now I have a page that lets you select a date and then select how many days the customer wants to stay for. So the selected date will be put towards the BookingDateIN field and the calculated date will be put towards the BookingDateOUT in a NOT BETWEEN SQL statement.
I have got this to work with some test data, how ever when I select a date range that is below the 5th day in any month it shows the rooms are booked and not available even though the test data does not contain any days below the 5th.
This is my test data in the Bookings Table:
BookingID
BookingDateIN
BookingDateOUT
CustomerID
RoomID
1
20/05/2010
23/05/2010
2
2
2
26/05/2010
28/05/2010
1
5
And here is my code for the bookings page:
<cfset CurrentPage=GetFileFromPath(GetBaseTemplatePath())>
<cfif isDefined("FORM.SearchRooms")>
<!-- adds the number of days to the selected date -->
<cfset #CalDate# = #DateFormat( DateAdd( 'd', #FORM.SelDays#, #FORM.SelDate# ), 'dd/mm/yyyy' )#>
<!-- Queries the Bookings table with a crazy NOT BETWEEN SQL Statement -->
<cfquery name="Check_Rooms_RS" datasource="HotelBookingSystem" username="HBSuser" password="HBSpass">
    SELECT *
    FROM Bookings
    WHERE BookingDateIN AND
    BookingDateOUT NOT BETWEEN
    <cfqueryparam value="#FORM.SelDate#" cfsqltype="cf_sql_timestamp">
    AND
    <cfqueryparam value="#CalDate#" cfsqltype="cf_sql_timestamp">
</cfquery>
<!-- Now this is my beginner CFQuery'n lol it queries the Rooms table with the values output from the bookings query and loops, then I put a 0 at the end to have the correct SQL statement lol I'm trying -->
<cfquery name="Rooms_RS" datasource="HotelBookingSystem" username="HBSuser" password="HBSpass">
SELECT *
FROM Rooms
WHERE RoomID = <cfloop query="Check_Rooms_RS">#RoomID# OR </cfloop>0
</cfquery>
</cfif>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hotel Booking System - User Manager</title>
<link rel="stylesheet" type="text/css" href="../style.css"/>
</head>
<body>
<div class="container">
    <div class="booking_choose_date">
         <cfparam name="PreSelDate" default="#LSDateFormat(Now(), 'dd/mm/yyyy')#">
<cfif isDefined("FORM.SearchRooms")>
    <cfset #PreSelDate# = #FORM.SelDate#>
</cfif>
        <cfform name="form1" width="375" height="350" action="#currentpage#">
<!-- Date Picker -->
           <cfinput type="DateField" name="SelDate" label="Block out starts" width="100" value="#PreSelDate#" mask="DD/MM/YYYY">
<!-- Day Picker -->
<cfselect size="1" name="SelDays" required="Yes" message="Select days staying">
      <option value="1" selected>1 Day</option>
      <option value="2">2 Days</option>
      <option value="3">3 Days</option>
      <option value="4">4 Days</option>
      <option value="5">5 Days</option>
      <option value="6">6 Days</option>
      <option value="7">7 Days</option>
</cfselect>
           <cfinput type="Submit" name="SearchRooms" value="Check" width="100">
        </cfform>
    </div>
     <cfif isDefined("FORM.SearchRooms")>
        <div class="search_results">
          <!-- Outputs the Bookings table RoomID values -->
            <cfoutput query="Check_Rooms_RS">
                 #Check_Rooms_RS.RoomID#
            </cfoutput>
          <!-- Outputs the Rooms table RoomID values -->
            <cfoutput query="Rooms_RS">
                 #Rooms_RS.RoomType#
            </cfoutput>  
        </div>
    </cfif>
</div>
</body>
</html>
Little help with this would be amazing !!

I only skimmed this thread. But even ignoring the myriad of date issues, the queries have a serious "logic" problem.  If you think about it, does searching for rooms that are not reserved in a table that only contains reserved rooms really make sense? Say you have twenty (20) rooms.  If only two (2) of them are reserved (ie in the Bookings table), how is that first query supposed to account for the other eighteen (18)?
It would make more sense to search the Bookings table for rooms that are reserved.  Then query your Rooms table for rooms not in that list (ie available).  Granted that is not a very efficient method for a real application. But should work for your purposes.
This is my test data in the Bookings Table:
Are you storing the booking dates as strings?  Dates should be stored in a date/time column.  Storing them as strings creates all kinds of problems. Not to mention it makes it more difficult to use your database's date functions.

Similar Messages

  • Need help to find out link between process order and purchase order.

    Hi All,
    Need help to find out link between process order and purchase order.
    We have purchase order, we can find out associated process order in MD09 (No Purchase Requisition found in Purchase order). When I tired to replicate this scenario with same material in system but not able to do.
    Please suggest me what needs to check to get purchase order link to process order.. (this is not subcontracting )
    Edited by: SAP PQ on Sep 26, 2011 5:24 PM
    Thanks,
    SAP PQ
    Edited by: SAP PQ on Sep 26, 2011 5:24 PM

    MD09 is pegging. In SAP pegging is dynamic, meaning that there's no fixed link between purchase order and process order in your case.
    This is why you did not get the same result when you tried again later.
    Such a link can exist only if you do direct procurement for the order.

  • I have updated my iphone this evening and is has asked me to connect my phone to itunes, I connected it to a computer with itunes and it says it needs restoring? and all my images etcwill be earsed I need help as I have not backed my iphone up previously

    I have updated my iphone this evening and is has asked me to connect my phone to itunes, I connected it to a computer with itunes and it says it needs restoring? and all my images etcwill be earsed I need help as I have not backed my iphone up previously please help?

    YOur phone is in recovery mode, any data that was on there is already gone, you will have to restore your phone and use whatever backup you to restore to.

  • I need help deleting and adding text

    i need help deleting and adding text, can soneone help
    Adobe Photoshop Elements 10

    You should delete your phone number from the topic line.
    Spambots search these forums for contact info.
    You don't want to get even more telemarketing/scam calls than you probably already get.
    It seems like the "Do Not Call" lists are ignored these days.
    Message was edited by: Bo LeBeau       Looks like someone already took care of this.

  • Hello,I need help.ipad 3 does not support flash media player.which player must I download instead of flash media player?

    Hello,I need help.ipad 3 does not support flash media player.which player must I download instead of flash media player?

    Flash is not supported on the iPad - and as Adobe have announced that they are stopping development on all mobile versions of it, it probably never will be.
    Browser apps such as Skyfire, iSwifter, Puffin and Photon 'work' on some sites, but judging by their reviews not all sites. Also some websites, especially news sites, have their own apps in the App Store.

  • Hi, I need help my computer is not starting up at all, nothing happening when I press the button on/off. The battery charger is working as using it for another laptop. Not sure what to do. Anyone have any idea? many thanks

    Hi, I need help my computer is not starting up at all, nothing happening when I press the button on/off. The battery charger is working as using it for another laptop. Not sure what to do. Anyone have any idea? many thanks

    You could try a SMC reset:
    http://support.apple.com/kb/HT3964
    If no change, do what Allan advises.
    Caio.

  • Hi I need help ..I do not know how to edit a pdf file that I scanned in,

    Hi I need help ..I do not know how to edit a pdf file that I scanned in, will someone please tell me what I should do PLEASE HELP

    What program are you using?  If it is just Adobe Reader you can not edit.
    Say thanks by clicking the Kudos Thumbs Up to the right in the post.
    If my post resolved your problem, please mark it as an Accepted Solution ...
    I worked for HP but now I'm retired!

  • Need Help in Simple SQL

    Hi,
    I need help. I did not know how to make this select statement run without error.
    select iif(max(numberseries) is null,'0',numberseries+ 1) from registration
    Thank

    Hi ,
    May i know what are you trying to do ,
    if you are trying to use if else in query, then it wont work
    if else is not valid in query.
    try to use decode or case , such that your need can be full filled
    Thank you
    Raj Deep.A

  • I need help scrolling and highlighting for a vast amount of pics that I'm trying to transfer. I have a macbook pro osx 10.5.8

    I need help scrolling and highlighting for a vast amount of pics that I'm trying to transfer. I have a macbook pro osx 10.5.8

    I need help scrolling and highlighting for a vast amount of pics that I'm trying to transfer. I have a macbook pro osx 10.5.8

  • Need help in establishing the connection between BO federator and Oracle DB

    Hi Experts,
    I am working on BO federator and now I need to establish the connection between BO federator and the oracle db to use this as the source for the federator,
    I know we need to download the respective oracle DB connect .jar file from the oracle web site and place it under the drivers section(folder) of the BO Federator.
    Now I need to understand what is/are the next steps I need to follow and what are the values for the following parameters which are required during establishing the connectivity while creation of data sources from federator end.
    Host Name:
    Port:
    SID:
    Schema:
    Please share the details, any help will be highly appreciated.
    Thanks with regards,
    Vinay

    Hi,
    Please find below details.
    Host Name: Server Name or IP Address (Oracle)
    Port: (oracle Server Port)
    SID:SID is a unique name for an Oracle database instance. -> To switch between Oracle databases, users must specify the desired SID <-. The SID is included in the CONNECT DATA parts of the connect descriptors in a TNSNAMES.ORA file
    Schema: no need to enter(Blank)
    Thanks,
    Amit

  • I have and ipod touch 4th gen and it will show up on my computer but not on my itunes i need help please and thank you

    I have an ipod touch 4th gen and when I plug it into my computer it shows up but it wont on iTunes and I was trying to put more music on it today and it wasn't showing up can u help please and thank you.

    Hey Babetta94,
    Thanks for using Apple Support Communities.
    After reviewing your post, the iPod is not recognized in iTunes. A frustrating situation to be sure. You haven't mentioned what OS the computer you are using uses. You can choose what article to use either OS X or Windows from this quoted section.
    iPod not appearing in iTunes
    http://support.apple.com/kb/TS3716
    If you have an iPod touch:
    For Windows: See iPhone, iPad, or iPod touch: Device not recognized in iTunes for Windows
    For Mac OS X: See iPhone, iPad, iPod touch: Device not recognized in iTunes for Mac OS X
    Have a nice day,
    Mario

  • Stalled Scrolling and Other Problems- NEED HELP ASAP! HAS NOT BEEN ANSWERED/SOLVED, STILL NEED HELP.

    Hello,
    Ever since I downloaded Firefox 25, I have had an issue with scrolling. If there was some way to record this, I would, but at this time I cannot, so a description will have to do. If someone knows a way to record what is happening, I will gladly do it to make what I am saying easier to visualize.
    On some sites I visit, scrolling will be what can only be described as "choppy"- I will attempt to scroll down, but there will be a small delay before the page responds and scrolls down. Thus, the scrolling does not go smoothly. This mostly happens on sites (tumblr pages especially) with non-scrolling backgrounds (ie backgrounds that do not scroll with the page) on them.
    First off, I do not think this is a problem with any extensions, my computer, or the sites themselves. When I open the same pages in Chrome, the issue does not occur and the issue does not occur in all pages.
    I have tried clearing the cookies and cache, resetting my browser, disabling hardware acceleration, checking the plugins (problem still happened even when all plugins were disabled), updating my graphics card, and disabling website colors. The first few produced no lasting result/fix, and while disabling website colors did fix the issue, it made the rest of the site/other sites (ones that were working fine) difficult/impossible to use.
    One interesting fact of note is this: If I downgrade to Firefox 24, the issue not only disappears, but stays away, and does not occur.
    Another fact of note: I have written a previous thread on this issue, but ended up not getting an answer to a second question I had. In the first thread, I was given this possible solution, referring to a bookmarklet I could use/try: https://support.mozilla.org/en-US/questions/976244#answer-496960
    So my questions here are these:
    1) What is going on in Firefox 25 that makes scrolling choppy in that version, but not in version 24 or any other browser except version 25?
    2) How exactly do I use that bookmarklet I linked to? Where do I need to place it? How do I get to where I need to place it? How would it work? Is there a way to/Can someone make it into a Greasemonkey (I have Greasemonkey) userscript, if it does work?
    Also, is there a way to "bump" my thread without actually commenting on it?

    Bumping this. Are my questions showing up for anyone else? Because usually I get fairly prompt answers, but have gotten nothing on my last couple of threads.
    I'm sorry if I'm coming off as demanding, but I would like to have this answered, and it's frustrating to not have things at least replied to.

  • I have forgot my password and need help. I have not synced my device with a computer so I can not restore it if any body can help please tell me. Thanks

    i forgot my passcode and have not snyced to a computer so I can not restore. Please help

    If you don't remember your iPad's passcode, you have to restore it as a new device.
    Read iOS: Forgot passcode or device disabled
    The passcode is quite secure. It would not be worthwhile to have one otherwise.

  • Need Help on List of Months between Two Dates

    Hello everyone,
    I have a table which has startdate & enddate, and need a SELECT statement to list all months between these two dates for each given ID.
    I did some test, and could not figure out how to get the startdate & enddate from testing table (instead of hard code them) in the select statement.
    Could anybody please help on it (Oracle 11gR2),
    Thanks in advance!!!
    create table testing(
    id          number,
    start_date  date,
    end_date    date);
    insert into testing values(100, to_date('05-FEB-2011', 'DD-MON-YYYY'), to_date('28-MAY-2011', 'DD-MON-YYYY'));
    insert into testing values(200, to_date('20-JUN-2011', 'DD-MON-YYYY'), to_date('28-DEC-2011', 'DD-MON-YYYY'));
    commit;
    select * from testing;
            ID START_DAT END_DATE
           100 05-FEB-11 28-MAY-11
           200 20-JUN-11 28-DEC-11
    Elapsed: 00:00:00.01
    *for testing.id = 100:*
    select to_char(add_months(to_date('05-FEB-2011', 'DD-MON-YYYY'), l - 1), 'YYYY-Mon') Dates
    from (select level l
           from dual
        connect by level <= months_between(trunc(to_date('28-MAY-2011', 'DD-MON-YYYY'), 'MONTH'),
                                           trunc(to_date('05-FEB-2011', 'DD-MON-YYYY'), 'MONTH')) + 1);
    DATES
    2011-Feb
    2011-Mar
    2011-Apr
    2011-May
    Elapsed: 00:00:00.01
    *for testing.id = 200:*
    select to_char(add_months(to_date('20-JUN-2011', 'DD-MON-YYYY'), l - 1), 'YYYY-Mon') Dates
    from (select level l
           from dual
        connect by level <= months_between(trunc(to_date('28-DEC-2011', 'DD-MON-YYYY'), 'MONTH'),
                                           trunc(to_date('20-JUN-2011', 'DD-MON-YYYY'), 'MONTH')) + 1);
    DATES
    2011-Jun
    2011-Jul
    2011-Aug
    2011-Sep
    2011-Oct
    2011-Nov
    2011-Dec
    7 rows selected.

    SQL> select * from testing
      2  /
            ID START_DAT END_DATE
           100 05-FEB-11 28-MAY-11
           200 20-JUN-11 28-DEC-11
    SQL> select  id,
      2          to_char(add_months(start_date,column_value - 1),'YYYY-Mon') dates
      3    from  testing,
      4          table(
      5                cast(
      6                     multiset(
      7                              select  level
      8                                from  dual
      9                                connect by add_months(trunc(start_date,'MM'),level - 1) <= end_date
    10                             )
    11                     as sys.OdciNumberList
    12                    )
    13               )
    14    order by id,
    15             column_value
    16  /
            ID DATES
           100 2011-Feb
           100 2011-Mar
           100 2011-Apr
           100 2011-May
           200 2011-Jun
           200 2011-Jul
           200 2011-Aug
           200 2011-Sep
           200 2011-Oct
           200 2011-Nov
           200 2011-Dec
    11 rows selected.
    SQL> SY.

  • New To Oracle.. Needs Help:: Conversion from SQL Server to Oracle 11g

    I am new to Oracle 11g and badly need the conversion of SQL Server Functions to Oracle.. Sample Pasted Code not working .. end with error.. pls help
    Create Table TempT (ID1 Varchar (10),
    ID2 Varchar (10)
    CREATE OR REPLACE PACKAGE GLOBALPKG
    AS
    TYPE RCT1 IS REF CURSOR;
    TRANCOUNT INTEGER := 0;
    IDENTITY INTEGER;
    END;
    CREATE OR REPLACE FUNCTION fTempT
    i IN VARCHAR2 DEFAULT NULL
    RETURN GLOBALPKG.RCT1
    IS
    REFCURSOR GLOBALPKG.RCT1;
    BEGIN
    OPEN REFCURSOR FOR
    SELECT TT.*
    FROM TempT TT
    WHERE (fTempT.i = ''
    OR TT.ID1 = fTempT.i)
    RETURN REFCURSOR;
    END;
    CREATE OR REPLACE FUNCTION fTempTF
    i IN VARCHAR2 DEFAULT NULL
    RETURN GLOBALPKG.RCT1
    IS
    REFCURSOR GLOBALPKG.RCT1;
    BEGIN
    OPEN REFCURSOR FOR
    SELECT *
    FROM TABLE(fTempT(i))
    RETURN REFCURSOR;
    END;
    LAST FUNCTION ENDs WITH ERROR
    Error(13,7): PL/SQL: ORA-22905: cannot access rows from a non-nested table item

    2. The major purpose is to get a simplest way to create a parameterized function who can return a table like output. 2nd function has no use instead i was testing the result of First Function like thisIf you just want to select from a select, you should use a view not a function.
    1. which program is more help ful for writing and executing queries bcoz after using Query Analyzer of Microsoft It seems difficult to work on SQL Developer.
    sqlplus? If you are having difficulty learning new tools because of an old one you used, probably best to forget the old one and concentrate on learning the new one because it will be different. This goes for the database itself also.
    2. Can DMLs be used within a Function.Yes, you just can't execute the function in another SQL statement if it modifies data and this is a good thing.
    3. Can temporary tables be used within a function.Unfortunately yes, but they shouldn't be unless you are in a slowest application competition.
    5. Each Function which is a Table Function must be accompanied with Type Definitions?? its a bit longer way of doing the things than SQL ServerThat is why it is better to use views instead, is there any reason you want a select that you can select from inside a function?
    SQL Server for last 9 years thats why i refer this toolThat is not in itself a problem, if you try and do what you did in SQLServer in Oracle, that will be a problem though.

Maybe you are looking for