Need help on my SQL statement

Hello experts,
I need to write a dynamic sql statement which will enable users to pick the date and the BI system will take them 3 months back. I tried 3 months variables I kept getting SQL error then I tried 90 days. Now it keep showing that there is no data which for sure I know its not trure.
This is my statement: +"GL Calendar"."Fiscal Date" >=timestampadd(SQL_TSI_DAY,-90, timestamp'@{ABCcost}{2013-05-16 00:00:00}')AND("GL Calendar"."Fiscal Date">=timestamp'@{ABCcost}{2013-05-16 00:00:00}')+
Anything that Im missing..

Rayan,
I am not sure if I am following you, cause we want to enable the user to pick whatever date and then from there they will get 3 months back and the rest of their info. I tried it didn't work, may be I placed at wrong place
Can you probably copy my statement above and insert in-between.
thanks,
Edited by: 994621 on May 17, 2013 11:28 AM

Similar Messages

  • Need help for the sql statement !!!!!

    hi all,
    i need a sql statement for a query, how can i get the result from the rownum between 100 and 150?
    plz help

    use a scrollable statement:
    PreparedStatement stat = Connection.prepareStement("select * from blah", ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_UPDATABLE);
    ResultSet rs = stat.executeQuery();
    rs.absolute(100);
    while (rs.next()) {
    String something = rs.get(1);
    Look into the JDK API reference for ResultSet to get an expalantion of scrollable statements.

  • Need help on coverting sql statement to NamedQueries

    hi, all,
    I have a problem on converting the following SQL statement returning last 10 records from an Oracle database.
    The SQL statement is as followings:
    select * from (select * from TABLE1 where ATT1 = 1 order by ATT2 desc) where rownum<11
    However, how should I convert this statement into NamedQuery?
    Thanks.

    Will the following SQL return the same set of rows for you:
    select * from TABLE1 where ATT1 = 1 order by ATT2 desc limit 1,10
    If so, that query is a lot easier to convert.
    I've never tried to convert a subquery into a NamedQuery. The problem is that you're not just converting to named query, but you're also changing from SQL to EJBQL, and they don't map directly even though the semantics are similar.

  • Need help in a sql statement

    Hi, I have some data like the following and I need to get only one row instead of two.
    Current data:
    ID                       Time_Type                       Time
    A_xyz Check_In 2009-02-11 07:00 AM
    A_xyz Check_out 2009-02-12 10:00 AM
    I want it in the following format:
    ID                       Check_in_Time                           Check_out_time
    A_xyz 2009-02-11 07:00 AM 2009-02-12 10:00 AM
    There are about 10 more fields in the table but all other data is same except for the time. Thanks for your help.

    Hi, Yes, I already had queries using max but then I found that I could not use them as I don't know how many time_types there would be. I appologize I should have mentioned this in my first post and had posted some additional info.
    In my example time_types are as check_in and check_out but infact the types are codes and they don't tell if they are check in or check out. All I need is to convert the rows into columns. I can call my columns col1, col2 etc instead of check_in_time and check_out_time.
    Also, I am giving you guys an example but it is exactly same as our real data.
    Thanks again.

  • Need help about distributed sql statement

    Hello everybody
    Enviroment:
    Oracle 11g R1.
    This Database was fine, 'till some days ago that a new system was deployed on other database. New system runs some SELECT querys to a my database using db_links. These statements are blocking some resources and 'cause that they are blocking many users of my database. I can see on Enterprise Manager this wait event : "enq: TM contention".
    Now my question is, why are these querys are blocking resources and users if they are only of type SELECT??? I thought that querys that did this were DML and DDL statements.
    Does this behavior is related with that those querys are executed by a distributed way (using dblinks)??
    Thanks a lot

    user652447 wrote:
    Distributed Transactions require commit even if a Select. See the following FAQ post from Jonathan Lewis for some basic information.
    http://www.jlcomp.demon.co.uk/faq/dblink_commit.html
    HTHNot always true though, it depends. The article you are linking to is quite old and covers, as stated, Oracle version(s): 7.0 – 9.2. Whereas the OP is on 11.
    http://download.oracle.com/docs/cd/B10500_01/server.920/a96521/ds_txns.htm
    In the section "Read-Only Response"
    Note that if a distributed transaction is set to read-only, then it does not use rollback segments. If many users connect to the database and their transactions are not set to READ ONLY, then they allocate *rollback space* even if they are only performing queries.
    In the OP's version
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17120/ds_txns003.htm#ADMIN12226
    Note that if a distributed transaction is set to read-only, then it does not use undo segments. If many users connect to the database and their transactions are not set to READ ONLY, then they allocate *undo space* even if they are only performing queries.
    However that doesn't account for the types of lock the OP is experiencing.

  • Need help with the session state value items.

    I need help with the session state value items.
    Trigger is created (on After delete, insert action) on table A.
    When insert in table B at least one row, then trigger update value to 'Y'
    in table A.
    When delete all rows from a table B,, then trigger update value to 'N'
    in table A.
    In detail report changes are visible, but the trigger replacement value is not set in session value.
    How can I implement this?

    You'll have to create a process which runs after your database update process that does a query and loads the result into your page item.
    For example
    SELECT YN_COLUMN
    FROM My_TABLE
    INTO My_Page_Item
    WHERE Key_value = My_Page_Item_Holding_Key_ValueThe DML process will only return key values after updating, such as an ID primary key updated by a sequence in a trigger.
    If the value is showing in a report, make sure the report refreshes on reload of the page.
    Edited by: Bob37 on Dec 6, 2011 10:36 AM

  • Help needed writing simple PL/SQL statement

    Hi,
    I need to run the following delete statement in a PL/SQL procedure but for it to commit every 1000 rows or so. Can anyone help?
    DELETE
    FROM IDIS.YPROCRULES A
    WHERE 1 = 1
    AND NOT EXISTS (SELECT 'X' FROM IDIS.YPROCCTRL B WHERE A.SEQ_0 = B.SEQ_0)
    Thanks
    Mark

    The fastest most efficient way of doing the delete is to write it in one sql statement as you have done.
    Commiting every 1000 rows means you have to use row by row processing. A lot of us call this slow by slow processing.
    Every time you commit in a loop , you increase the risk of snapshot too old error, plus you actually slow down the processing, as well as give you issues with regards to what happens if your process fails after x iterations. (some of your data is commited, other data is not, how do you restart the process)
    The correct approach is to have appropriately sized rollback/undo segments.

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

  • Help with an sql statement

    String Queue = jComboBox3.getSelectedItem().toString();
    String Start_Date = jComboBox2.getSelectedItem().toString();
    String End_Date = jComboBox1.getSelectedItem().toString();
    int bins []= new int [size];
    String sql = "SELECT Count(Accepts.Queue)FROM Accepts WHERE Accepts.Queue = 'Queue' And (Accepts.TimeOfAccept Between 'Start_Date' And 'End_Date');";
    ResultSet result = stmt.executeQuery(sql);
    if (result.next())
    int res = result.getInt(1);
    for (int k = size; k<0; k--)
    for (int i = 0; i<res+1; i++)
    bins[i] = res% k;
    Im trying to get information from a table using an sql statement i have converted the items selected in combo boxes into strings and am using these strings in the sql statement but it is still wrong can anyone help me

    . . . WHERE Accepts.Queue = 'Queue' And (Accepts.TimeOfAccept Between 'Start_Date' And 'End_Date')As others have mentioned, it looks like you have a data type mis-match.
    Try:
    . . . . . Accepts.TimeOfAccept Between TO_DATE(Start_Date) AND TO_DATE(End_Date)
    This assumes that the two DATE variables - Start_Date and End_Date - are in standard format - DD-MON-YY.
    If not, you will need to supply a format model as a second argument to the TO_DATE functions:
    TO_DATE(character_string , format_model)
    i.e.
    . . . . . BETWEEN TO_DATE(Start_Date,'MM/DD/YY') AND TO_DATE(End_Date,'MM/DD/YY')
    Hope this helps.

  • Need help creating valid XHTML statement

    Hi -
    This is for a homework assignment that requires valid XHTML (I have to validate the dynamically generated HTML). Everything is great with the servlet except the statements where I "echo" the user input.
    The user inputs several values (loan calculator servlet), hits submit and if the values are valid inputs, the servlet returns the amount of the monthly payment. It also displays the inputs in case the user wants to change one of them (loan amount, interest rate or term of the loan).
    The servlet output is fine but my problem is in validating the html. The W3C validator shows an error on the lines where I'm echoing the original inputs.
    Here's my code that generates the html:
    out.println("<td><input type=\"text\" name=\"amount\" value=" + amount + "><br/></td>");Here's the html line that is output:
    <td><input type="text" name="amount" value=783745.43><br/></td>For this to be valid XHTML, the value needs to be in quotes. For example, that parameter should be value="783745.43".
    This is the error that the validator produces:
    Error Line 16 column 43: an attribute value specification must be an attribute value literal unless SHORTTAG YES is specified.
    <td><input type="text" name="amount" value=783745.43><br/></td>The 'shorttag' and 'omittag' make no sense to me; I haven't found a decent reference yet on how to use them.
    I've tried multiple combinations of escape sequences but have had no success. Can anybody point out what I'm overlooking?
    Thanks in advance.

    I have understand about the SQL statement.
    My problem is like this. I have 3 variable. I have a table with 3 field.
    How can I use those variable to reftrieve value from my select statement?
    How can I use those variable to send value to my update or insert statement?
    sample statement:
    - select F1, F2, F3 from T where F1 = V1
    - insert into F1, F2, F3 values(V1, V2, V3)
    please help, I'm working on my final project in college.
    Thanks before.
    "Sweet devil is still as sweet as ever..."

  • 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

  • Power Query for Excel - Need Help with Oracle SQL Syntax

    Hello everyone,
    I am new to Power Query and am not able to figure this out.  I am trying to pull in data into my Excel spreadsheet using a specific Oracle SQL query.  While in query editor, how do I take the Oracle.Database function and add my SQL statement? 
    I already know what I want, I don't want it to download all the table names.  According to the help page, I should be able to do this but it does not provide a syntax example
    Also, I don't understand what "optional options as nullable record" means.
    Below is what function and arguments the help page notes.  How do I use this?
    Oracle.Database(server as text, optional options as nullable record) as table
    Any help is greatly appreciated.
    Thank you,
    Jessica

    When I try this, I get an error 
    DataSource.Error: Oracle: Sql.Database does not support the query option 'Query' with value '"Select * from Owner.View_Name"'. Details: null
    I'm trying to download oracle data from a view into power query - Power Query navigator does not list th eviews from my source, it lists only the tables. When I try write sql statements, it throws me the above
    error. This is what I tried
     Oracle.Database("Source/Service",[Query="Select * from Owner.View_Name"])
    Any ideas how to fix this? 

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

  • 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

Maybe you are looking for

  • How to deploy OHW onto Oralce Application Server?

    I down load the demo-bundle. It is set in c:\ohw\. I startup the OC4J from c:\ohw\bin. And the help system can be launched from URL http://localhost:8888/. Also I modify the Oracle Application (in Jdeveloper 10g1.3.2.0) to make it work with the helps

  • Updating projects with activities linked to other projects.

    Im kind of new at this. I am working on a project with several contracts. i am thinking of setting up each contract as a separate project in an EPS and linking the milestones in all the projects to create a master schedule. On a weekly basis i reciev

  • Hidding password in JTextField

    Hi there, which command I use to hide the password in a JTextField? Am i obligated to hand-treat it ? name: **** <- typed word...

  • InDesign CS2 & Leopard: Place & Export dialog box areas cutoff

    I am having severe problems with InDesign CS2 and Leopard, and before anyone says "upgrade to CS3", we can't. Almost every time I go to place a graphic or export a PDF, the system hangs for a few seconds with the wheel spinning, then InDesign just qu

  • Feature LGMST and Batch input failure

    Hi - My bdc recording is not taking into a account HR feature LGMST.  The  feature LGMST is automatically recalculating and replacing the exempt wagetype with a non-exempt wagetype when exempt employees move from an exempt position to a non-exempt po