Condition variable for sql query

I have created the follwing query which adds the open sales orders and forecasts to create a projected cashflow.  The query works fine except I would like to be able to enter the forecast code, rather than have it hard coded.  If I enter Where OFCT.code='[%0]', I get no results for the forecast. 
SELECT     FCT1.ItemCode "Item", FCT1.Date "Date", FCT1.Quantity "Qty", ITM1.Price "Price", (FCT1.Quantity*ITM1.Price)"Ext Price"
FROM         OFCT INNER JOIN
                      FCT1 ON OFCT.AbsID = FCT1.AbsID INNER JOIN
                      ITM1 ON FCT1.ItemCode = ITM1.ItemCode
WHERE     (ITM1.PriceList = '2') AND (OFCT.Code ='5/24/2010')
UNION
SELECT          RDR1.ItemCode "Item", RDR1.ShipDate "Date", RDR1.Quantity "Qty", RDR1.Price "Price", (RDR1.Quantity*RDR1.Price)"Ext Price"
FROM          RDR1
WHERE          RDR1.LineStatus = 'O' and  RDR1.OpenQty >'0'
ORDER BY DATE
Edited by: Sandra Clavell on May 27, 2010 3:50 AM
Edited by: Sandra Clavell on May 27, 2010 3:51 AM

Try this:
Declare @fcod char(16)
set @fcod/* select f.code from ofct f where f.code*/='[%0]'
SELECT FCT1.ItemCode "Item", FCT1.Date "Date", FCT1.Quantity "Qty",
ITM1.Price "Price", (FCT1.Quantity*ITM1.Price)"Ext Price"
FROM OFCT INNER JOIN
FCT1 ON OFCT.AbsID = FCT1.AbsID INNER JOIN
ITM1 ON FCT1.ItemCode = ITM1.ItemCode
WHERE (ITM1.PriceList = '2') --AND (OFCT.Code =@fcod)
UNION
SELECT RDR1.ItemCode "Item", RDR1.ShipDate "Date", RDR1.Quantity "Qty",
RDR1.Price "Price", (RDR1.Quantity*RDR1.Price)"Ext Price"
FROM RDR1
WHERE RDR1.LineStatus = 'O' and RDR1.OpenQty >'0'
ORDER BY DATE

Similar Messages

  • Passing values in a vector list as bind variables in sql query.

    Hi,
    I have a vector list containing values 12,13,14.
    vector<string> v;
    v has values 12,13 and 14.
    Here the number of values in vector list are not fixed.
    I want to pass these values as bind variables to sql query.
    Can anyone suggest me how to do this.
    Thanks in advance!!

    Ah, the it's the classic 'Varying In-List' again
    See:
    The Tom Kyte Blog: Varying in lists...
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:110612348061 (started more than a decade ago, so scroll down for more recent examples)

  • Bind variables in SQL query of DBAdapter

    Hi,
    Can we add bind variables to SQL query when we define DB adapter...?

    No, not in the Wizard.
    I do not know if it is possible with the TopLink in combination with BPEL.
    But can you use a Pl/SQL procudere/package that performs the dynamic SQL?

  • IF NEW VARIABLE IN SQL QUERY, DISPLAYS AS LAST COLUMN + rpad not working

    Hello everybody and thank you in advance,
    1) if I add a new variable to my sql query to select a column which was already in the table, it shows it in the report table as the Last column to the right. That is, if I add "street" to
    something like city, postcode, street, store, manager, etc, instead of placing street between postcode and store, it places it as i said as the last column to the right.
    2) When values are entered into the cells of the tables, yes, they do expand it to their needed lenght, But, only if it is one word. If it is two, like when i enter the value "very good"
    then it takes two lines so as with a carriage return within the cell, thus, making it too high the row. I tried to padd spaces with rpad but it did not work. something like rpad(stock, 20,' ')
    I must say that the table is in the same page where there is a Form, so as the table grows in lenth it is actually squeezing the form located right on its left.
    3) rpad did not work with the most simple syntax, but less would with what i need because it turns out i am using DECODE in order to do a conversion between value displayed and
    value returned in my select list of values, something like : DECODE (TO_CHAR (stock),'1','Deficient','2','Average','3','Good','4','Very Good',null) AS stock,
    so, i have tried to put the rpad there in several places but either it gave parsing error or it left the column empty not picking any values.
    thank you very much
    Alvaro

    Alvaro
    1) That is standard behaviour of apex builder. You can change the display order with the arrows in the report attributes column report.
    2) You will have to play with the style attributes of the column to accomplice this. For instance style="white-space:pre;" in the Element Attributes of the column attributes. White-space:normal would thread several space (' ') as 1. So no matter how many you add with rpad they will be shown as 1.
    Or set a width either as attibute or in a style class for that column.
    Nicolette

  • Passing Session State Variables to SQL query

    Hi,
    I am using 3 pages in my application build by APEX 3.1.2. Login Page, Report Page and Form Page.
    I am using LDAP authentication for Login Page and I want the user session information to be feeded to the filter query
    being used to display data on Report Page. Is there any way to do that. I know
    there is one variable %LDAP_USER% which is using the userid given on login
    page. But I dont know how to use APEX session variables to filter query. Need
    assistance on that stuff.
    Thanks,
    Gaurav

    Hi Gaurav,
    Session "variables" (global items, application items and page items) can be accessed using v('ITEM_NAME') (for strings) or nv('ITEM_NAME') (for numbers) within sql queries/procedures/triggers etc.
    If you look at the Substitution Strings section here: http://download.oracle.com/docs/cd/E10513_01/doc/appdev.310/e10499/index.htm#S you'll find more information about this and a list of items that you can use that are set by Apex itself.
    Andy

  • Passing variables to SQL query from checkboxes

    Hello,
    I have a cursor which gets different ids from an id table. The cursor is something like this:
    CURSOR id IS
             SELECT distinct id_ FROM I
                      order by id_;I then iterated through the cursor to made checkboxes to choose multiple ids:
    FOR i IN id
           LOOP
            htp.p('<tr>
           <DIV align="left"><td><input type="checkbox" name="option" value=ID '||i.id_||'> </td></tr>');
             htp.p('<font size="'||3||'">'
             ID'||i.id_||'</a></font>'
             ||'</a>' );
           htp.br;                       
           END LOOP;The values of the checkboxes were extracted by:
    var ids ="";
    for (var j = 0;j < document.form.option.length; j++)
                 if (document.form.option[j].checked)
                     ids = ids + document.lf.option1[j].value + "\n";
            }I have the following SQL query:
    Select * from Persons where Identification = ...; I would like to use to pass the values of the checkboxes (i.e. the variable ids ) to my SQL query. I want the user to select multiple values for the checkboxes. For example, they can select 4 and 3. I want to pass the difference to my SQL query....that is, I want the id to be 1. So, I want this:
    Select * from Persons where Identification = 1; Any ideas how to do this? Also my code above is in different procedures within a single package.

    Your requirement is not very clear. What happens when you select 3 checkboxes? What will be the difference between them? How do you pass that information to the oracle report?

  • Passing SessionBean variable to sql query editor

    Hi,
    I am trying to pass a variable that I define locally in SessionBean to sql query via the query editor.
    SELECT ALL comments.id,
                        comments.comment,
                        comments.comment_date
    FROM comments
    WHERE comments.id = **SessionBean1.id**How do I specify **SessionBean1.id** in the WHERE clause?
    Thanks for your help.
    --izumi                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Use this SQL query:
    SELECT ALL comments.id,
                        comments.comment,
                        comments.comment_date
    FROM comments
    WHERE comments.id = ?Then in the page that uses this (wherever the query is executed) provide the variable value with:
    <your row set name>.setObject(1, getSessionBean1().getCommentId());

  • Inline transform for Sql Query not working in SAP MII 12.1 Version 12.1.8 B

    Hi All,
    I applied an xslt for an sql query which returns an xml file.
    I used inline transform icon in sql query to load an xsl file which has to return me a string
    Any idea why is not working for me..?
    My Sample XML file:
                                     <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="/XMII/CM/BatchDisposition/BatchQueueManagement/StyleSheets/ProductXsl.xsl"?>
    <Rowsets DateCreated="2011-05-05T07:27:45" EndDate="2011-05-05T07:27:45" StartDate="2011-05-05T06:27:45" Version="12.1.8 Build(20)">
         <Rowset>
              <Columns>
                   <Column Description="ProductName" MaxRange="1" MinRange="0" Name="ProductName" SQLDataType="12" SourceColumn="ProductName"/>
              </Columns>
              <Row>
                   <ProductName>Asprin 100mg Tablets 12 x10 strip</ProductName>
              </Row>
              <Row>
                   <ProductName>Asprin 300mg Tablets 12 x10 strip</ProductName>
              </Row>
              <Row><ProductName>Ibprooven 200mg Tablets 12 x 10 strip</ProductName></Row>
              <Row><ProductName>RipTide 50mg Tablets 40 x10 strip</ProductName></Row>
              <Row><ProductName>Seroquel 200mg Tablets 6 x10 strip</ProductName></Row>
              <Row><ProductName>Seroquel 400mg Tablets 12 x10 strip</ProductName></Row>
         </Rowset>
    </Rowsets>
    My Sample XSl File:
                                    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
         <xsl:text>["</xsl:text>
         <xsl:for-each select="Rowsets/Rowset/Row">
              <xsl:value-of select="ProductName"/>
              <xsl:if test="position() &lt; last()">
                   <xsl:text>","</xsl:text>
                    </xsl:if>
              <xsl:if test="position()=last()">
                           <xsl:text>"]</xsl:text>
                    </xsl:if>
         </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
    Any Suggestions  are Welcome:
    Thanks

    Something like this should work...
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:template match="/">
              <Rowsets DateCreated="{Rowsets/@DateCreated}" Version="{Rowsets/@Version}" StartDate="{Rowsets/@StartDate}" EndDate="{Rowsets/@EndDate}">
                   <xsl:copy-of select="/Rowsets/FatalError"/>
                   <xsl:copy-of select="/Rowsets/Messages"/>
                   <Rowset>
                   <Columns>
                        <Column Description="Mycol1" MaxRange="1" MinRange="0" Name="Mycol1" SQLDataType="12" SourceColumn="Mycol1" />
                   </Columns>
                   <Row>
                   <Mycol1>
                   <xsl:text>["</xsl:text>
                        <xsl:for-each select="/Rowsets/Rowset/Row">
                             <xsl:value-of select="." />
                             <xsl:choose>
                                  <xsl:when test="position() &lt; last()"><xsl:text>","</xsl:text></xsl:when>
                                  <xsl:otherwise><xsl:text>"]</xsl:text></xsl:otherwise>
                             </xsl:choose>
                        </xsl:for-each>
                   </Mycol1>
                   </Row>
                   </Rowset>
              </Rowsets>
         </xsl:template>
    </xsl:stylesheet>

  • Get a insert session value for SQL query at report

    Hi friends
    I created a global temp table and procedure to support web search form.
    and a search result report. The procudure
    gets search result from multip tables and
    insert into temp table --recordsearch. I can get value from temp table  by call procedure
    at SQL*Plus.
    However, I can not get this value by web report.
    How can I get this insert session value and pass to SQL query for report?
    Thanks,
    Newweb
    CREATE GLOBAL TEMPORARY TABLE recordsearch
    (emp_id          VARCHAR2(200),
    ssn               VARCHAR2(9),
    fname          VARCHAR2(200),
    lname           VARCHAR2(200),
    m_name          VARCHAR2(200)
    ) ON COMMIT PRESERVE ROWS;

    it possible that your web form does not have a persistent, dedicated connection. if you have connection pooling for example, multiple sessions will see the same instance of the GTT, so if one deletes it, then nobody sees it (or you can see others data). if the connections are not persistent, then they can disconnect between calls, deleting the GTT table.

  • Xml parsing error while selecting whole result set for sql query

    Hi All,
    I am having xml parsing error while selecting whole query result set. The data is coming fine for default result set of 50 rows.
    My exception is below.
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00234: namespace prefix "xsi" is not declared
    Error at line 1
    ORA-06512: at "SYS.XMLTYPE", line 254
    ORA-06512: at line 1
    *31011. 00000 - "XML parsing failed"*
    **Cause: XML parser returned an error while trying to parse the document.*
    **Action: Check if the document to be parsed is valid.*
    My sql query is below that is giving results for default result set of 50 rows.
    select extract(xmlType(clob_xml_colm_name), '//v2:node1//childnode/text()','xmlns:v2="namespace_url"').getStringVal()  from table_name
    My sql developer version is below.
    Java(TM) Platform     1.7.0_04
    Oracle IDE     3.1.07.42
    Versioning Support     3.1.07.42
    My database version is below.
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit
    Please could any one help me urgently as the sql query is supposed to be correct as it is returning query results, but the problem happening when i try to select whole result set.
    Thanks and regards,

    What does the XML look like? It appears that some of the supposed XML stored as a CLOB is not really valid XML. Find the row in the table that is causing your issue and review the "XML" in it.

  • Create a validation for SQL Query (updateable report)

    Hello
    I have a need for creating a validation on a SQL Query (updateable report)- type region
    1)
    When a row get populated i don't want same values to be populated in the second row.(as shown in first 2 rows)
    Also, I don't want to have a value that falls in range in between 100 and 1000 for the period falls in the previous. (as shown in third row)
    i.e
    Type_id
    Lower_Limit        Upper_Limit           Date_From       Date _To
    1
    100                      1000                   1/1/2013        12/31/2013
    2
    100                      1000                    1/1/2013        12/31/2013
    3
    101                       500                    2/1/2013        10/31/2013
    appreciate any help
    thanks
    kp

    This example could help:
    http://apex.oracle.com/pls/otn/f?p=31517:214
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • I am not able to see the trace files for SQL query

    Hello, I am using windows vista OS.
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE 10.2.0.3.0 Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    SQL>
    I enabled the trace as below
    alter system set timed_statistics=TRUE
    alter system set sql_trace=TRUE
    After this, I ran sql query from scott as below.
    select count(*) from emp;
    After this, i checked in user dump directory. The trace files are generating... But this sql code is not appearing in the trace files...
    Am i missing anything... Any help is appreciated.
    Thanks

    This may happen when the trace file is not completely closed.You may try again doing like this,
    alter session set sql_trace=true;
    select * from emp;
    alter session set sql_trace=false;After this,disconnect and exit from your session as well. This should close the file completely and you should be able to see your command in it.
    HTH
    Aman....

  • Setup variables for BEx Query

    Dear all,
    I am working on a BEx query. I would like to show MTD and YTD actual & planned expenses. My questions are as follows:
    (1)      how can I set up variables or variants which can look up the system date to calculate the MTD and YTD date? For example, I execute the query without input the date and I would like the query automatically look up the date for YTD  (e.g. 1/1/2009 u2013 2/20/2009) and MTD (2/1/2009 u2013 2/20/2009) for actual expenses?
    (2)     Since the planned data is by year and distribute 12 months equally and not by day, how can I set up variables which can look up the system date to calculate the number of the days from the beginning of the year up to today and beginning of the month update to today so I can calculate the MTD and YTD planned expenses based on the annual budget.
    Thanks

    Thanks Reddy,
    Since my variable for planned data is not date variable anymore, it is a factor = current date / number of days in current month and I used this to multiple by the planned monthly data.  If I used entire month and  the plan data will be overvalue, I can't compare to the MTD actual data since actual date is updated by day.  How can I create a variable for this and use it to caluclate in the BEx Query?
    I believe the function will work but I don't know much about ABAP.  I try to search sample code for the function.  here is what I get but I don't think it is going to work. Can you point out what is missing? I believe I need to put it under 'ZXRSAU01'
    Under CASE I_DATASOURCE
    I put
    WHEN 'ZMTDFACTOR'. #the variable name of the MTD factor
    PERFORM ZMTDFACTOR_EXIT.
    In ZMTDFACTOR_EXIT  and here is the code I get so far
    WHEN 'ZMTDFACOTR'.
        DATA:  SDT TYPE SY-DATUM,
              MON_FACTOR TYPE N,
              ST_CD(2) TYPE N,   
              ST_LD(2) TYPE N.     
                l_date_in  type sy-datum,
                l_date_out type sy-datum.
              SDT = SY-DATUM.
    *current date
              ST_CD = SDT+6(2).
    CONCATENATE l_v_calmonth '01' into l_t_range-low.
    l_date_in = l_t_range-low.
    CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'
      EXPORTING
        day_in                  = l_date_in
    IMPORTING
       LAST_DAY_OF_MONTH       = l_date_out
    EXCEPTIONS
       DAY_IN_NOT_VALID        = 1.
    *last date
    ST_LD = l_date_out+6(2).
    *Calculate the factor based on the MTD
    MON_FACTOR = ST_CD / ST_LD.
    How can I send MON_FACTOR to ZMTDFACOTR and back to the query?
    Thanks again.

  • Need Heip For SQL Query

    Hi Friends,
    I am too muchconfused about an sql query. I've created a html page where I select one radio button . The value of this radio button is passed to the query.Now the out put of the query is used in developing the output.
    For illustration I show you the source code.
    Radio Button Selection page.
    <form action="service.html" method="post"> <h3><strong>Services Available</strong></h3>   <p>     <label>       <input type="radio" name="service" value="si"  />       Institutions</label>     <br />     <label>       <input type="radio" name="service" value="sc" />       Corporate_Offices</label>     <br />     <label>       <input type="radio" name="service" value="sr" />       Restaurent_Cafe</label>     <br />     </p>   <label>     <input type="submit" value="Submit" />   </label> </form>
    Now the query page-
    <sql:query var="empList" scope="session"> select <c:out value="${param.service}" /> from map_service where cityname = ? <sql:param value="${param.cityname}" />   </sql:query>
    Now I need to generate output with the given below value in the next page-
    <c:out value="${param.service}" />
    This value show value as si, sc sr only where I need the database table value as per selection.
    I am really confused that what I should write as <c:out value="${...
    My database table has attributes as cityname, si, sc, sr. etc.
    when some one select si from radio button the value of radio button is passed to sql query and the value which is selected on the table after query should be used in developing output result please help.

    Dear Friend Is it not possible for any of you to give me a clue that if I've to get the output of *?* from the query what I can write in syntax.
    <sql:query var="empList" scope="session">
    select ? from map_service
    where cityname = ?
    <sql:param value="${param.service}" />
    <sql:param value="${param.cityname}" />
    </sql:query>
    <c:out value="${empList.param.service}" />Output of the value of ? from the database select ? from map_service Any idea

  • No Data Found for SQL query

    Hello,
    I have a simple SQL query in a report.
    select
          null as "Complete",
             a.col1,
             a.col2,
             a.col3,
             a.col4,
          b.col2
    from      TableA a, TableB b
    where   a.id = b.idThere is a known issue in apex 4.0 that is causing the "When No Data Found" message to work incorrectly so that this is returned:
    report error:
    ORA-01403: no data found
    Is there a way to return a message in a SQL statement? If not, any suggestions on how I can convert this in the existing report to PL/SQL would be appreciated.
    Thanks!
    Matt

    I would like to do something similar to this (below) but the only option that is given other than "SQL Query" is “PL/SQL function body returning a SQL query”
    I'm not sure how to do this as a funciton.
    declare
    vComplete Varchar2;
    vCol1        Varchar2;
    vCol2        Varchar2;
    vCol3        Varchar2;
    vCol4        Varchar2;
    vColB2      Varchar2;
    Begin
    select
             null as "Complete",
             a.col1,
             a.col2,
             a.col3,
             a.col4,
             b.col2
    into vComplete,vCol1,vCol2,vCol3,vCol4,vColB2
    from   TableA a, TableB b
    where   a.id = b.id
    Dbms_output.put_line(vComplete,vCol1,vCol2,vCol3,vCol4,vColB2);
    Exception
          When no_data_found
                Dbms_output.put_line(vComplete,vCol1,vCol2,vCol3,vCol4,vColB2);
          When others
                Dbms_output.put_line(‘exception handling message’);
    End;

Maybe you are looking for