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

Similar Messages

  • I need help on This SQL problem ASAP :)

    Hi All,
    I need help on this....
    I have a table...
    Say table name: one
    with these values
    premnum status
    1234 C
    1234 F
    1234 P
    1234 F
    5678 C
    5678 F
    5678 P
    9112 C
    9112 F
    9112 P
    9112 F
    3456 C
    3456 F
    3456 P
    7890 C
    7890 P
    7890 F
    Now, I want to output only those premnum with status = 'C' and those premnum with Status 'F' having a count > 1 (with two status = 'F')
    So the output would be something like this
    premnum status
    1234 C
    1234 F
    1234 F
    5678 C
    9112 C
    9112 F
    9112 F
    3456 C
    7890 C
    I really need help on this asap...
    I need the SQL statement on this....
    Thank you in advance. :)
    Edited by: 804697 on Oct 23, 2010 9:45 PM

    Hi,
    you can use the following query.
    CREATE TABLE PREM_TEST ( premnum NUMBER , STATUS VARCHAR2(1));
    INSERT INTO PREM_TEST VALUES(1234 ,'C');
    INSERT INTO PREM_TEST VALUES(1234 ,'F');
    INSERT INTO PREM_TEST VALUES(1234 ,'P');
    INSERT INTO PREM_TEST VALUES(1234 ,'F');
    INSERT INTO PREM_TEST VALUES(5678 ,'C');
    INSERT INTO PREM_TEST VALUES(5678 ,'F');
    INSERT INTO PREM_TEST VALUES(5678 ,'P');
    INSERT INTO PREM_TEST VALUES(9112 ,'C');
    INSERT INTO PREM_TEST VALUES(9112 ,'F');
    INSERT INTO PREM_TEST VALUES(9112 ,'P');
    INSERT INTO PREM_TEST VALUES(9112 ,'F');
    INSERT INTO PREM_TEST VALUES(3456 ,'C');
    INSERT INTO PREM_TEST VALUES(3456 ,'F');
    INSERT INTO PREM_TEST VALUES(3456 ,'P');
    INSERT INTO PREM_TEST VALUES(7890 ,'C');
    INSERT INTO PREM_TEST VALUES(7890 ,'P');
    INSERT INTO PREM_TEST VALUES(7890 ,'F');
    SELECT     PREMNUM , STATUS
    FROM     PREM_TEST
    WHERE     STATUS = 'C'
    OR          (PREMNUM , STATUS ) IN (     SELECT PREMNUM , STATUS
                                                 FROM     PREM_TEST
                                                 WHERE     STATUS = 'F'
                                                 GROUP BY PREMNUM , STATUS
                                                 HAVING COUNT(*) > 1
    PREMNUM S
    1234 C
    1234 F
    1234 F
    5678 C
    9112 C
    9112 F
    9112 F
    3456 C
    7890 C
    9 rows selected.

  • 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.

  • Hi all, need help in PL SQL?

    I am new in this industry. I have my training going on ORACLE PL SQL.
    Can somebody help me out:
    1.) How do we write program to add two numbers and then printing them as output.
    2.) How do we write program to read from a file and then write to another file.
    3.) How do we write program to send an email from your program.
    4.) How do we write program to create random numbers.
    Thanks in advance. . .

    Hello;
    This forum is dedicated for Oracle Beehive, if you need help and advices on SQL/PL-SQL please open a thread on the following forum: PL/SQL
    About your third question, if you want to send an email from Beehive the best way is to perform that through the Web Services.
    Fred

  • Need Help with simple array program!

    Hi, I have just recently started how to use arrays[] in Java and I'm a bit confused and need help designing a program.
    What this program does, it reads in a range of letters specified by the user. The user then enters the letters (a, b or c) and stores these characters into an array, which the array's length is equal to the input range the user would enter at the start of the program. The program is then meant to find how many times (a,b and c) appears in the array and the Index it first appears at, then prints these results.
    Here is my Code for the program, hopefully this would make sense of what my program is suppose to do.
    import B102.*;
    class Letters
         static int GetSize()
              int size = 0;
              boolean err = true;
              while(err == true)
                   Screen.out.println("How Many Letters would you like to read in?");
                   size = Keybd.in.readInt();
                   err = Keybd.in.fail();
                   Keybd.in.clearError();
                   if(size <= 0)
                        err = true;
                        Screen.out.println("Invalid Input");
              return(size);
         static char[] ReadInput(int size)
              char input;
              char[] letter = new char[size];
              for(int start = 1; start <= size; start++)
                   System.out.println("Please enter a letter (a, b or c) ("+size+" max), enter # to stop:");
                   input = Keybd.in.readChar();
                   while((input != 'a') && (input != 'b') && (input != 'c') && (input != '#'))
                        Screen.out.println("Invalid Input");
                        System.out.println("Please enter a letter (a, b or c) ("+size+" max, enter # to stop:");
                        input = Keybd.in.readChar();
                                    while(input == '#')
                                                 start == size;
                                                 break;
                   for(int i = 0; i < letter.length; i++)
                        letter[i] = input;
              return(letter);
         static int CountA(char[] letter)
              int acount = 0;
              for(int i = 0; i < letter.length; i++)
                   if(letter[i] == 'a')
                        acount++;
              return(acount);
         static int CountB(char[] letter)
              int bcount = 0;
              for(int i = 0; i < letter.length; i++)
                   if(letter[i] == 'b')
                        bcount++;
              return(bcount);
         static int CountC(char[] letter)
              int ccount = 0;
              for(int i = 0; i < letter.length; i++)
                   if(letter[i] == 'c')
                        ccount++;
              return(ccount);
         static int SearchA(char[] letter)
              int ia;
              for(ia = 0; ia < letter.length; ia++)
                   if(letter[ia] == 'a')
                        return(ia);
              return(ia);
         static int SearchB(char[] letter)
              int ib;
              for(ib = 0; ib < letter.length; ib++)
                   if(letter[ib] == 'b')
                        return(ib);
              return(ib);
         static int SearchC(char[] letter)
              int ic;
              for(ic = 0; ic < letter.length; ic++)
                   if(letter[ic] == 'c')
                        return(ic);
              return(ic);
         static void PrintResult(char[] letter, int acount, int bcount, int ccount, int ia, int ib, int ic)
              if(ia <= 1)
                   System.out.println("There are "+acount+" a's found, first appearing at index "+ia);
              else
                   System.out.println("There are no a's found");
              if(ib <= 1)
                   System.out.println("There are "+bcount+" b's found, first appearing at index "+ib);
              else
                   System.out.println("There are no b's found");
              if(ic <= 1)
                   System.out.println("There are "+ccount+" c's found, first appearing at index "+ic);
              else
                   System.out.println("There are no c's found");
              return;
         public static void main(String args[])
              int size;
              char[] letter;
              int acount;
              int bcount;
              int ccount;
              int ia;
              int ib;
              int ic;
              size = GetSize();
              letter = ReadInput(size);
              acount = CountA(letter);
              bcount = CountB(letter);
              ccount = CountC(letter);
              ia = SearchA(letter);
              ib = SearchB(letter);
              ic = SearchC(letter);
              PrintResult(letter, acount, bcount, ccount, ia, ib, ic);
              return;
    }     Some errors i get with my program are:
    When reading in the letters to store into the array, I get the last letter I entered placed into the entire array. Also I believe my code to find the Index is incorrect.
    Example Testing: How many letters would you like to read? 3
    Enter letter (a, b or c) (# to quit): a
    Enter letter (a, b or c) (# to quit): b
    Enter letter (a, b or c) (# to quit): c
    It prints "There are no a's'" (there should be 1 a at index 0)
    "There are no b's" (there should be 1 b at index 1)
    and "There are 3 c's, first appearing at index 0" ( there should be 1 c at index 2)
    The last thing is that my code for when the user enters "#" that the input of letters would stop and the program would then continue over to the counting and searching part for the letters, my I believe is correct but I get the same problem as stated above where the program takes the character "#" and stores it into the entire array.
    Example Testing:How many letters would you like to read? 3
    Enter letter (a, b or c) (# to quit): a
    Enter letter (a, b or c) (# to quit): #
    It prints "There are no a's'" (should have been 1 a at index 0)
    "There are no b's"
    and "There are no c's"
    Can someone please help me??? or does anyone have a program simular to this they have done and would'nt mind showing me how it works?
    Thanks
    lou87.

    Without thinking too much...something like this
    for(int start = 0; start < size; start++) {
                System.out.println("Please enter a letter (a, b or c) ("+size+" max), enter # to stop:");
                input = Keybd.in.readChar();
                while((input != 'a') && (input != 'b') && (input != 'c') && (input != '#')) {
                    Screen.out.println("Invalid Input");
                    System.out.println("Please enter a letter (a, b or c) ("+size+" max, enter # to stop:");
                    input = Keybd.in.readChar();
                if(input == '#') {
                        break;
                letter[start] = input;
            }you dont even need to do start = size; coz with the break you go out of the for loop.

  • Need Help With Simple ABAP Code

    Hello,
    I'm loading data from a DSO (ZDTBMAJ) to an Infocube (ZCBRAD06). I need help with ABAP code to some of the logic in Start Routine. DSO has 2 fields: ZOCTDLINX & ZOCBRDMAJ.
    1. Need to populate ZOCPRODCD & ZOCREFNUM fields in Infocube:
        Logic:-
        Lookup /BI0/PMATERIAL, if /BIC/ZOCBRDMAJ = /BIC/OIZOCBRDMAJ
        then /BIC/ZOCPRODCD = ZOCPRODCD in Infocube
               /BIC/ZOCREFNUM = ZOCREFNUM in Infocube         
    2. Need to populate 0G_CWWTER field in Infocube:
        Logic:
        Lookup /BIC/PZOCTDLINX, if /BIC/ZOCTDLINX = BIC/OIZOCTDLINX
        then G_CWWTER = 0G_CWWTER in Infocube.
    I would need to read single row at a time.
    Thanks!

    I resolved it.

  • Need help on a sql query

    Hi Friends,
    I am trying to load Employees and their Assignments using APIs.
    I have various columns in my staging table like Last Name, First Name, etc., but I need help in writing query in the cursor especially for columns Emp Number and Supervisor Number.
    I have data as below
    Emp_Number     Supervisor_Number
    GE0002               GE0064
    GE0064               EG0009
    EG0009               EG0001
    100009                EG0001
    EG0001               TU0001
    Cursor I write will process the data in the same order as above, but here the problem is...
    When it processes first row, it checks for supervisor GE0064 which do not exist and so it errors out.
    Similarly for second row, it checks for supervisor EG0009 which again do not exist and so it errors out.
    So in order to prevent this, the cursor should process the rows as below
    Emp_Number     Supervisor_Number
    EG0001               TU0001
    EG0009               EG0001
    GE0064               EG0009
    GE0002               GE0064
    100009                EG0001
    By this way, Supervisor should be defined first as an employee and then it can be used as a supervisor for other employees
    is there a way that I can get the output as above(second set of data), when the table has records randomly as above(first set of data)
    Appreciate your help!
    Thanks,
    Srikanth

    Srikanth wrote:
    ... but the number of records returned by above query are lot more than number of records in the table.
    Why did the number go up?
    It's something only you can find out
    Maybe some Emp have several Supervisor(s) like
    with
    t as
    (select 'GE0002' Emp,'GE0064' Supervisor from dual union all
    select 'GE0064','EG0009' from dual union all
    select 'EG0009','EG0001' from dual union all
    select 'GE0064','100009' from dual union all
    select '100009','EG0001' from dual union all
    select 'EG0001','TU0001' from dual
    select Emp,Supervisor,lpad('_',3 * (level - 1),'_')||Emp indent
      from (select Emp,Supervisor
              from t
            union all
            select supervisor,null
              from t tt
             where not exists(select null
                                from t
                               where emp = tt.supervisor
    start with Supervisor is null
    connect by prior Emp = Supervisor
    EMP
    SUPERVISOR
    INDENT
    TU0001
    TU0001
    EG0001
    TU0001
    ___EG0001
    100009
    EG0001
    ______100009
    GE0064
    100009
    _________GE0064
    GE0002
    GE0064
    ____________GE0002
    EG0009
    EG0001
    ______EG0009
    GE0064
    EG0009
    _________GE0064
    GE0002
    GE0064
    ____________GE0002
    Regards
    Etbin

  • I need help with simple problems. im a student.

    i'd like to be advanced with my studies so i will post questions.. i need help on how to answer. thank you.
    1. create a java program that will evaluate if the value entered is a positive, negative, vowel, consonant and special characters.
    im actually done with the positive and negative using if else statements.. i used an integer data type. now my question is how do conjoin the characters when i need to evaluate a vowel and a consonant. i cant use char either. please help. i dont know what to do yet.
    2. create java program that will translate the input from numbers to words. e.g. input:123 output: one hundred twenty-three.
    i have an idea to use a switch case statement. but i have no idea on how will i be able to do it. so if you guys can help me.. well then thankies..

    Welcome to the Sun forums. First, please note that you have posted in the wrong forum. This forum is for topics related to Sun's JavaHelp product. You should post your questions in the New to Java forum.
    As part of your learning, you will have to develop the ability to select an approach to a problem, create a design that reflects that approach, and then implement the design with code that you create.
    So, it's inappropriate for us to take the problem statement that you have been given and short-circuit your learning process by giving you the implemented problem solution. We can comment on the individual questions that you may have, and point out problems and errors that we see in the code that you develop.
    As a hint, when you are stuck, forget about Java and programming. Just start with a sheet of paper and a pencil, and figure out how to layout the task on paper. The consider how to translate that to programming.
    If you have problems, post short example code that shows the problem, and explain your question clearly. We can't read minds.
    Make sure you post code correctly so that it's not mangled by the forum software, and so that formatting is maintained. Select your typed or pasted code block and press the CODE button above the typing area.

  • Need help in simple function

    Hi,
    i am using sql developer to write a simple function .which need to get job details by using employ number
    ..below is the function
    CREATE OR REPLACE
    FUNCTION Q_JOB(empno1 in emp.empno%type) RETURN VARCHAR2 AS
    job1 varchar2(100);
    BEGIN
    select job into job1 from
    emp where empno=empno1;
    dbms_output.put_line('job :'||job1);
    RETURN job1;
    END Q_JOB;
    when i am trying to run this using command
    execute q_job(7369);
    i am getting folowing error..
    PL/SQL: Statement ignored
    06550. 00000 - "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:
    can any one tell whats exact problem is?

    You can use execute only for procedures, not functions.
    You have different possibilities:
    * If you like issuing the statement from a worksheet, use an anonymous block:
    DECLARE
      v_job  emp.job%type;
    BEGIN
      v_job = q_job(7369);
    END;
    / * Alternatively, use your function in SQL:
    SELECT q_job(7369) FROM DUAL; * For editing and testing your PL/SQL code, sqldev has very cool features: editor, compiler and debugger.
    Under the Functions node under your connection, you'll find your function: right-click and Edit it. Just above your code you have a mini-toolbar to Compile your code, Run or Debug it. A lot more on this inside the Help topics.
    Using the last 2 possibilities will provide you the returned value, so using dbms_output in your function isn't even necessary.
    Have fun,
    K.

  • Need help in using SQL in a jsp file to compare date and time

    hi every one,
    Actually I am doing a project using JSP. I need to compare a date field in the database (MS Acess) to the current system date and time. I have to do this in a select statement.
    I have alredy defined a variable of type Date in the JSP file and I am comparing this variable to the date in the database through a select statemant.
    Here is what I am doing
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
              java.util.Date today = new java.util.Date();
              String myDate=sdf.format(today);
    query = "SELECT Car_ID, Model_ID, Year, Ext_Color, Price from Cars where EDate <= "+myDate+" ;";
    EDate is the feild in the database and it's format is (5/12/2008 5:29:47 PM) it is of type Date/Time in MS Acess.
    when I execute the query it gives the following error
    SQL error:java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'EDate <= 2008-10-16 08:10:07'.
    I hope any one can help me with that error and answer my question, I've tried too many things but nothing helps
    Thanks in advance :-)

    Hi,
    When the comparision is needed to be done with the current date , we don't need to send in Java
    Date then format it and compare with MS Acess Date.
    In MS Access we have Date() function which will give you the current date.
    So you can try rewriting your query as following :
    query = "SELECT Car_ID, Model_ID, Year, Ext_Color, Price from Cars where EDate <= Date() ;"; ---------------------
    Hope this helps.
    Thanks

  • Need help on Dynamic SQL Cursor in Forms

    Hi All,
    I am trying to execute Dynamic SQL Cursor in forms using EXEC_SQL built in.
    I have a cursor for example:
    'select * from supplier where supplier = '||p_supplier||' and processing_order = '||p_order
    My code is
    cur_num := Exec_SQL.Open_cursor;
    sql_order := 'select * from supplier where supplier = '||p_supplier||' and processing_order = '||p_order;
    EXEC_SQL.PARSE(cursor_number, sql_order);
      EXEC_SQL.DEFINE_COLUMN(cur_num ,1,ln_Supp_Id);
      EXEC_SQL.DEFINE_COLUMN(cur_num ,2,ls_Suppl_Name,30);
    EXEC_SQL.DEFINE_COLUMN(cur_num ,24,ls_exchange,20);
      sql_count := EXEC_SQL.EXECUTE(cur_num );
      While EXEC_SQL.FETCH_ROWS(cur_num ) > 0 Loop
            EXEC_SQL.COLUMN_VALUE(cur_num ,1,ln_Supp_Id);
            EXEC_SQL.COLUMN_VALUE(cur_num ,2,ls_Suppl_Name);
            EXEC_SQL.COLUMN_VALUE(cur_num ,24,ls_exchange);
    End Loop;
    EXEC_SQL.CLOSE_CURSOR(cur_num );
    In this case I have to write 24 Define Columns and 24 Column value. Is there any way to assign them to %rowtype at one time as I need all coulmn of the table.
    I had similar case on multiple tables.
    Please help me
    Thanks,
    Maddy

    I need this dynamic sql because p_supplier and p_order values changes at run time
    I do not understand. Is this a simplified sample or the real thing? You do know that you can pass variables to cursors:
    cursor test is
    select * from supplier where supplier = p_supplier and processing_order = p_order;
    or does e.g. p_supplier hold other parts of the query?
    cheers

  • Need help:Urgent:MS SQL Server and J2EE Server

    Hello,
    i am developing simple bean managed persistence bean. i want to know how could i use microsoft SQL Server as my database with ejb's in J2EE. i don't want to use cloudscape rather i want to connect through jdbc bridge with sql server. can any body help me out ?
    i have developed DSN for my database with the name of DsnProduct and user name for DB is guest and password is guest123.
    so do i have to change configuration is my J2EE server . or put some additional code. so far i have added the following line in my implementation class
    private String dbName= "java:comp/env/jdbc/ProductDB";
    DataSource ds = (DataSource) ic.lookup(dbName);
    con = ds.getConnection("guest","guest123");
    moreover in server configuration i have added driver
    sun.jdbc.odbc.JdbcOdbcDriver
    and also provide the following JNDI Name
    jdbc/ProductDB
    and
    it's url is
    jdbc:odbc:DsnProduct
    i am thankfull for your support.
    [email protected]

    hi llturro,
    Thanks for answering my question. I have tried out what you suggested, but I still can't fix my problem. The following are the messages that display when I try to run my servlet. It seems that the DataSource, Connection and Statement are ok, however when it comes to the ResultSet the error message appear. What's wrong with my ResultSet coding ?
    ResultSet rs = stat.executeQuery("SELECT ISBN FROM BOOKSINFO WHERE ISBN='"+primarykey+"'");
    setEntityContext Method
    Find by primary key
    DataSource OK
    Connection OK
    Primary Key = 013-00-675721-9
    Statement OK
    java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
    java.rmi.RemoteException: Unknown Exception/Error thrown by EJB method.; nested exception is:
    java.lang.NullPointerException
    java.rmi.RemoteException: Unknown Exception/Error thrown by EJB method.; nested exception is:
    java.lang.NullPointerException
    java.lang.NullPointerException
    <<no stack trace available>>

  • 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.

  • Need help on small sql query

    Hi,
    I have a requirement where I need to show 'F&D' string. I can explain this by below query.
    select 'F&D' from dual
    but when I run this query, toad prompts me to enter value for &D variable :( But my requirement is to show 'F&D' string.
    Can anyone please tell me what modification needs to be done to above query to get string 'F&D' as output.
    I know work around for this as below.
    select 'F'||chr(38)||'D' from dual
    I want permenant solution for this. Can anyone please help me?
    Thanks
    Shantanu

    see if below make difference
    SQL> select 'F&D' from dual ;
    Enter value for d: &D
    old   1: select 'F&D' from dual
    new   1: select 'F&D' from dual
    'F&
    F&D
    SQL> select 'F'||'&'||'D' from dual ;
    'F'
    F&D

  • Need help creating large SQL query

    I am trying collect the sum of records that have a cancelled event prior to the Arrive event. The solution needs to be within the Sum function. Any ideas would be helpful
    The structure of the table is as follows
    1. Record_Num(primary): varchar
    2. Event_Type: varchar
    3. Time: timestamp
    Each record number can contain multiple events, hence the issue with specifiying the time for an event of 'Arrive' and an event of 'Canceled'
    This is part of a much bigger query, here's what that looks like:
    Select
    Sum(Case when di.calltype = 'Missed' then 1 else null end) as "Canceled Prior To Liftoff",
    Sum(Case
    when dt.eventtype = 'Canceled' Then 1
    when
    (select to_char(dt.datetimestamp, 'HH:MI:SS')
    from progpennstar.dispatchtime dt
    where Lower(dt.eventtype) in 'aborted')
    < any (select to_char(dt.datetimestamp, 'HH:MI:SS')
    from progpennstar.dispatchtime dt
    where dt.eventtype in 'Arrive Locale')
    Then 1
    Else null end) as "Canceled Enroute to Call"
    From progpennstar.dispatch di, progpennstar.dispatchtime dt
    where di.dateoftransport >= to_date('07/01/2008', 'MM/DD/YYYY') and
    di.dateoftransport <= to_date('09/30/2008', 'MM/DD/YYYY') and
    di.dispatch_id = dt.dispatch_id

    to the op: I think SomeoneElse already got the solution, I just want to add a few minor points. You can replace the ANY construct (which is rarely used) with a simple comparison. In general ANY constructs are more difficult to understand. Check if the correct logic is applied.
    SELECT SUM(CASE
                   WHEN di.calltype = 'Missed' THEN 1
                   ELSE NULL
               END) AS "Canceled Prior To Liftoff"
          ,SUM(CASE
                   WHEN dt.eventtype = 'Canceled' THEN 1
                   WHEN dt.eventtype = 'Aborted'
                   AND  exists (SELECT null
                                        FROM dispatchtime dt2
                                        WHERE dt2.eventtype IN 'Arrive Locale'
                                        AND dt2.dispatch_id = di.dispatch_id
                                        AND dt.datetimestamp < dt2.datetimestamp /* this is the new comparison */
                         THEN   1
                   ELSE  NULL
               END) AS "Canceled Enroute to Call"
    FROM   dispatch di,
           dispatchtime dt
    WHERE  di.dateoftransport >= to_date('07/01/2008', 'MM/DD/YYYY')
    AND    di.dateoftransport < to_date('09/30/2008', 'MM/DD/YYYY') /* Carefull! I changed <= to <. Do you want to include the full last day or only midnight?  */
    AND    di.dispatch_id = dt.dispatch_id;I also changed the alias of the remaining subquery so that different aliases are used.
    Edited by: Sven W. on Dec 11, 2008 1:01 PM

Maybe you are looking for