SQL Query Calculating Price based on logic

Hi Experts,
Here is my table records,
SHIPMENT_ID     SHIP_PRICE     SHIP_ADDT_PRICE     PRODUCT_ID     PRODUCT_QTY
1000          3.95          1          12          2
1000          0          0          17          1
1000          6.95          2          11          4
1001          0          0          17          1
1001          12.95          1          12          2
1001          12.95          2          11          4
1002          0          0          17          1
1002          20.95          1          12          2
1002          20.95          2          11          4For Each Shipment:
I need to get maximum shipprice (no need to consider product and qty).
then to manipulate as follows from existing sample records such as
SHIPMENT_ID     SHIP_PRICE     
1000          (1*6.95)+(4-1*2)     -- Maximum Price Calculation for particular shipment
1000          (1*0)               -- Other product calculation for same shipment
1000          (4*2)               -- Other product calculation for same shipment
1001          (1*12.95)+(4-1*2)     -- Maximum Price Calculation for particular shipment
1001          (1*0)               -- Other product calculation for same shipment
1001          (4*2)               -- Other product calculation for same shipment
1002          (1*20.95)+(4-1*2)     -- Maximum Price Calculation for particular shipment
1002          (1*0)               -- Other product calculation for same shipment
1002          (4*2)               -- Other product calculation for same shipment
Max Shipprice Row for each Shipment
(SHIP_PRICE)+(remaining PRODUCT_QTY if PRODUCT_QTY>1 + SHIP_ADDT_PRICE)
Other than Max shipprice for each shipment
(PRODUCT_QTY + SHIP_ADDT_PRICE)
I am struggling here with logic how to proceed it, Any suggestions related to this?
Thanks,

Hi,
Sorry to disturb you again, it seems the requirement is not met correct.
The given answer just worked out for that data. May be i have not conveyed correctly.
Here is what i need
Table Records
SHIPMENT_ID     SHIPMENT_PRICE     SHIPMENT_ADDT_PRICE     PRODUCT_ID     PRODUCT_QTY     VIRTUAL_COLUMN (Just for your Reference)     
1000          6.95          2               11          4          1
1000          6.95          2               11          4          2
1000          3.95          1               13          2          3
1000          3.95          1               12          2          4
1001          12.95          2               11          4          5
1001          12.95          1               13          2          6
1001          12.95          2               11          4          7
1001          12.95          1               12          2          8
1002          20.95          1               12          2          9
1002          20.95          2               11          4          10
1002          20.95          2               11          4          11
1002          20.95          1               13          2          12
Repeated values in table with Maximum Value,
SHIPMENT_ID     SHIP_PRICE     SHIPMENT_ADDT_PRICE     PRODUCT_QTY     PRODUCT_ID     VIRTUAL_COLUMN
1000          6.95          2               4          11          1
1000          6.95          2               4          11          2
1001          12.95          2               4          11          5
1001          12.95          2               4          11          7
1002          20.95          2               4          11          10
1002          20.95          2               4          11          11*
In this Case, There are two rows same with maximum value for all three shipments,
but need to take one row as maximum and to consider the other as like not maximum row to process the logic
I have considered the Record with VIRTUAL_COLUMN value 1,5 and 10 as maximum value and others as not maximum values
Expected Result (For Each Row) - Just listed for one shipment_id = 1000 here
SHIPMENT_ID     SHIP_PRICE     CALCULATION          STEPS                                        VIRTUAL_COLUMN     
1000          41.7          (1*6.95)+((4-1)*2)     Maximum ShipPrice + (PRODUCT_QTY-1)*SHIPMENT_ADDT_PRICE          1
1000          8          (4*2)               PRODUCT_QTY*SHIPMENT_ADDT_PRICE                         2
1000          2          (2*1)               PRODUCT_QTY*SHIPMENT_ADDT_PRICE                         3
1000          2          (2*1)               PRODUCT_QTY*SHIPMENT_ADDT_PRICE                         4*Note: The virtual column in the provided data is just for reference and not exists in table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Dynamic sql query for report based on user input

    Hi everyone,
    I have built custom search fields (name, date born, gender etc.) in the search region and in the results region a report need to be displayed.
    Now I'm not very experienced with Apex or Oracle sql, but could anyone telll me how to first check if a user filled in a field and then build a query based upon what field the user filled in to submit.
    Any help would be appreciated, thanks in advance.
    regards,
    Cleo
    Edited by: Cleopatra on Jan 18, 2011 5:51 AM

    Hi, Cleopatra. Welcome to OTN!
    If you don't have too many fields instead of checking to see if they're filled in you can use OR conditions in yoru WHERE_CLAUSE to check for NULLS to ignore NULLS, something like (you will have to test this carefully!)
    AND some_column = NVL(:P24_1,some_column)the idea being that if the field is NULL then the column will match itself - in this case assuming the column itself does not have a null value

  • Sql query unit price

    Hello Together,
    how can i find the unit price for an item with an query.
    I used this query:
    SELECT $[$34.0.68] FROM [dbo].[OITM]
    WHERE
    OITM.ItemCode = '10000-0000'
    but with the result '0' as price but in the item i have 5 $ as unit price.
    Thank you and best regards
    Edited by: Serkan Er on Oct 22, 2009 1:59 PM

    OH ok,
    i just want possibilitty to select the actual unit Price from the item master data.
    In the item master data we put in the field Price_List:  pricelist_1.
    Concerning this field the system shows us the Unit-Price for this item which is in the pricelist_1.
    In SQL i can find a table named OPLN - the records are only the information pricelist1, pricelist2 , e.g.
    how can i find the details to this records - for example pricelist_1
    is there a related table ????????????????

  • Discrepancy between Select Expert and SQL Query

    Greetings.  I am having an issue with a report, but I think it's more cosmetic and may not be causing a functional issue...
    When I go into the Report...Select Expert...Record, I see that my criteria for the report is .AND. logic.
    When I go into the SQL Query view, it shows .OR. logic...
    After I verify the database, the SQL query still does not get updated.  Saving and re-opening the report still does not update. 
    Is there any reason this will never match?  Thanks in advance.

    Sorry.  I am on Crystal 12.  Database is SQL 2005.
    I didn't think the detail mattered much, but the select expert shows:
    isnull({NONCONFORMANCE.CLOSED_DATE}) and
    not isnull({NONCONFORMANCE.PRODUCT_ID}) and
    not({NONCONFORMANCE.PRODUCT_ID}= '') and
    not({NONCONFORMANCE.PRODUCT_ID}= ' ')
    SELECT N.NCM_ID, N.NCM_DATE, N.PRODUCT_ID, N.CLOSED_DATE, N.ENTITY_ID
    FROM   NONCONFORMANCE N
    WHERE  N.CLOSED_DATE IS  NULL  AND N.PRODUCT_ID IS  NOT  NULL  AND  NOT (N.PRODUCT_ID='' OR N.PRODUCT_ID=' ') AND N.ENTITY_ID='CHI'
    Now that I look at how the SQL is generated (after cleaning up the statement), it's the negatives that got me.  I originally had a problem with the report that was pulling back blanks and spaces.  I made changes and I didn't pay close enough attention to what exactly changed in the SQL...  It appears to be the way the logic in the Select Expert is converted to SQL.
    I just need to start using Command more often and write my own SQL instead of using the Select Expert!!!

  • Oaf: putting validation in VO based on sql query

    Hi All,
    I need few inputs for the customization of OAF page.
    Business Need: Restriction of special character in supplier oaf pages for supplier name.
    There are 3 oaf pages involved in supplier creation/update for R 12.1.3
    1)     oracle\apps\pos\supplier\webui\OrganizationPG (underlying VO is sql query based).
    2)     oracle\apps\pos\supplier\webui\QuickUpdatePG (underlying VO is sql query based).
    3)     oracle\apps\pos\supplier\webui\SuppCrtPG (underlying VO is based on EO - HzPuiOrgProfileQuickEOEx) .
    For pages referring EO, we have extended the underlying EO and override the validateEntity() method to throw the OAAttrValException. After substitution, validation is working.
    For VO based on query, the standard AM’s are instantiating the VO and using Rowimpl class they are setting the attributes.
    Question: How to enforce validation logic in VO or AM in such cases where oracle standard code is instantiating the VO dynamically?
    One possible solution is to use the PPR event on input text message bean and catch it in custom controller’s processFormRequest method and before super. processFormRequest(), we can put the validation.
    Is there any other way to achieve it?

    VO extension will not work as the
    Standard Controller code : oracle.apps.pos.supplier.webui.QuickUpdateCO is calling the AM's method on the click of save button and AM is dynamically invoking the methods in VO.
    Standard Controller code:
    OAApplicationModule oaapplicationmodule = oapagecontext.getApplicationModule(oawebbean);
    if(oapagecontext.getParameter("btnSave") != null)
    oaapplicationmodule.invokeMethod("updateVendor");
    oaapplicationmodule.invokeMethod("updateVendorSites");
    oaapplicationmodule.getTransaction().commit();
    Corressponding standard standard AM code...
    CallableStatement callablestatement;
    Exception exception;
    oadbtransaction = getOADBTransaction();
    connection = oadbtransaction.getJdbcConnection();
    Object obj = null;
    oaviewobjectimpl = (OAViewObjectImpl)findViewObject("SupplierVO");
    callablestatement = null;
    try
    callablestatement = oadbtransaction.createCallableStatement(" BEGIN savepoint upd_vndr_ab ; END;", 0);
    callablestatement.executeQuery();
    catch(SQLException sqlexception1)
    throw OAException.wrapperException(sqlexception1);
    finally
    if(callablestatement == null) goto L0; else goto L0
    if(callablestatement != null)
    try
    callablestatement.close();
    catch(SQLException sqlexception) { }
    break MISSING_BLOCK_LABEL_97;
    try
    callablestatement.close();
    catch(SQLException sqlexception2) { }
    throw exception;
    VendorsVORowImpl vendorsvorowimpl;
    label0:
    oaviewobjectimpl.reset();
    vendorsvorowimpl = (VendorsVORowImpl)oaviewobjectimpl.first();
    String s = vendorsvorowimpl.getPosModified();
    String s1 = vendorsvorowimpl.getHzModified();
    Number number = vendorsvorowimpl.getVendorId();
    int i = number.intValue();.....
    Extending the VO will not server the good as the handle will not be given to extended class....
    Edited by: user13791631 on Jun 20, 2012 9:29 PM

  • Putting validation in VO based on sql query

    Hi All,
    I need few inputs for the customization of OAF page.
    Business Need: Restriction of special character in supplier oaf pages for supplier name.
    There are 3 oaf pages involved in supplier creation/update for R 12.1.3
    1)     oracle\apps\pos\supplier\webui\OrganizationPG (underlying VO is sql query based).
    2)     oracle\apps\pos\supplier\webui\QuickUpdatePG (underlying VO is sql query based).
    3)     oracle\apps\pos\supplier\webui\SuppCrtPG (underlying VO is based on EO - HzPuiOrgProfileQuickEOEx) .
    For pages referring EO, we have extended the underlying EO and override the validateEntity() method to throw the OAAttrValException. After substitution, validation is working.
    For VO based on query, the standard AM’s are instantiating the VO and using Rowimpl class they are setting the attributes.
    Question: How to enforce validation logic in VO or AM in such cases where oracle standard code is instantiating the VO dynamically?
    One possible solution is to use the PPR event on input text message bean and catch it in custom controller’s processFormRequest method and before super. processFormRequest(), we can put the validation.
    Is there any other way to achieve it?

    {forum:id=210} is the OAF forum

  • Validation in VO based on sql query

    I need few inputs for the customization of OAF page.
    Business Need: Restriction of special character in supplier oaf pages for supplier name.
    There are 3 oaf pages involved in supplier creation/update for R 12.1.3
    1)     oracle\apps\pos\supplier\webui\OrganizationPG (underlying VO is sql query based).
    2)     oracle\apps\pos\supplier\webui\QuickUpdatePG (underlying VO is sql query based).
    3)     oracle\apps\pos\supplier\webui\SuppCrtPG (underlying VO is based on EO - HzPuiOrgProfileQuickEOEx) .
    For pages referring EO, we have extended the underlying EO and override the validateEntity() method to throw the OAAttrValException. After substitution, validation is working.
    For VO based on query, the standard AM’s are instantiating the VO and using Rowimpl class they are setting the attributes.
    Question: How to enforce validation logic in VO or AM in such cases where oracle standard code is instantiating the VO dynamically?
    One possible solution is to use the PPR event on input text message bean and catch it in custom controller’s processFormRequest method and before super. processFormRequest(), we can put the validation.
    Is there any other way to achieve it?

    {forum:id=210} is the OAF forum

  • Troubles with af:treeTable based on ViewObject after replacing SQL query.

    Hi everyone!
    We have <af:treeTable> component in our application, based on 3 ViewObject instances. These instances have the following structure in the Application Module:
    RootViewObject
    |----MainViewObject
    |----------|--------------ManagedViewObject
    According to our business logic, we change SQL query programmatically, reexecute all queries, refresh <af:treeTable> component, but the content of our tree table does not change after these actions. I have tried to output content of ViewObjects after changing and reexecuting the queries, and I have found out that the data in the ViewObjects have been changed!
    Why does the content of the <af:treeTable> component NOT change after refreshing it programmatically?
    Any ideas?
    Thanks in advance!
    Edited by: Emin10 on 10.12.2012 0:28
    Edited by: Emin10 on 10.12.2012 0:28

    Kamaal, Saif Kamaal
    I've already tried to put PPR on the parent container (in my case this is a toolbarButton).
    I refresh treeTable programmatically using this code:
    RequestContext rc = RequestContext.getCurrentInstance();
    rc.addPartialTarget(mytreeTable);

  • Bold a single row in a Report based on SQL Query

    Should be easy? So, how do I bold a single row in a report based on SQL query without creating a new template or writing Java for the page? What is the Tabular Form Element "Element Attributes" field for? Or what am I supposed to put in there to make it do anything?

    One way to do this is to add a hidden column to your report which contains the formatting value, for example:
    select empno
    , ename
    , sal
    , decode(empno,1,'font-weight:bold','font-weight:normal') style
    from emp
    Hide the STYLE column.
    Then you can use this column for each column in Column Formatting > HTML expression in this way:
    <span style="#STYLE#">#SAL#</span>
    Unfortunately you have to do this for each colum you want to appear bold.
    good luck,
    Dirk Dral

  • Report based on PLSQL returning SQL query

    I created function which builds the SQL and returns it as VARCHAR2. For testing purposes I harcoded the primary ID for the query to be based on. I run the function as standalone call to get the generated SQL and to test it. It works fine. The moment I try to use the ID parameter as an argument passed to the function it doesn't work and I get the "No data found" error. Again if I try this function outside of Apex it produces correct SQL syntax and it runs.
    The function signature is really simple:
    FUNCTION abc(i_id NUMBER) RETURN VARCHAR2
    IS
    l_id NUMBER;
    BEGIN
    -- this works:
    -- l_id := 300;
    -- this doesn't work:
    l_id := i_id;
    ... more code follows. It uses the l_id while building the query.
    I also tried to make it an anonymous block and place it directly in Apex region. Again I face the same problem. I modified this function slightly to reference the page attribute instead of accepting parameter:
    DECLARE
    l_id NUMBER;
    BEGIN
    -- this works:
    -- l_id := 300;
    -- this doesn't work:
    l_id := :P65_ID;

    Have you verified that i_id and P65_ID have a value when the procedure runs? Perhaps have something along the lines of "if i_id is null then return 'select <dummy data> from dual' else [build real query here]"...?
    -D.

  • Include Button that executes PL/SQL procedure to SQL query based region

    I would like to add two columns to a SQL query region.
    These columns would not be sourced from the query, but rather would be used to execute a PL/SQL procedure.
    For example, I would like to have a manager approve or deny adding an additional employee to the department.
    There would be one button for APPROVE. And, one button for DENY.
    The PL/SQL procedure would execute to perform the required DML based upon the selected action (either APPROVE or DENY).
    A sample output would look like this:
    <APPROVE>, <DENY>, John Doe, Accountant
    <APPROVE>, <DENY>, Jane Doe, Accountant
    Is there any way to add a button to a SQL Query based report region where that button executes a stored proc? If so, what is the basic process for doing this?
    Thanks!
    -Reid

    Is there any way to add a button to a SQL Query based report region where that button executes a stored proc? If so, what is the basic process for doing this?Conditional page item? You can associate processes with buttons on a page

  • Is there a way to consolidate calculations used in SQL Query Data Sets?

    I am building SQL Query Data Sets against multiple DB Views which all have different date formats. I have the date parameter working well, but want to consolidate the changes that I have to do to it especially for the quarter. For example the SQL against a monthly view would use "where year_month > to_char(:ST_DATE, 'YYYY-MM')" which is not too hard, but to make that work for the quarterly view I need several concats and a decode to get a "> '2012-Q2'". I would like not to have to do this within every where clause. I had put this into a global element hoping to use that in a filter for the data set, but the filter does not have access to global elements only parameters.
    Is there any way to refer to a calculated global element from the data set to do this? I am using Layout Templates, so even if I wanted to I could not do the condition within the template.
         Thanks,
         Rick

    Change the following line to include the red coloured parts
    <div class="MasterColumn" spry:repeat="ds4" spry:setrow="ds4" spry:hover="MasterColumnHover" spry:select="MasterColumnSelected">
      <span>{Dsp_#}</span><span>{Dsp_WkDay}</span><span>{Dsp_Event}</span>
    </div>
    The add the following style rule to your document:
    .MasterColumn span {
        display: inline-block;
    I hope this helps.
    Ben

  • Setting current values in Multiple Select List in SQL Query based Report

    Hi,
    I have a report based on a sql query that contains a multiple select list. Unfortunately I cannot get the multiple select list to display the current values (p_value) correctly. I have created a page item, :p311_current_versions, that is set using a pre-header process and it returns a value with a colon delimited format e.g. '10.1.2.1.0:10.1.2.2.0'. Then this item is used in the sql query to set the current value (p_value) of the apex_item.select_list_from_query function. However when the table is displayed, instead of having two entries, 10.1.2.1.0 and 10.1.2.2.0 selected, it has an extra entry '10.1.2.1.0:10.1.2.2.0' selected.
    Here is my code:
    select distinct a.product, a.version from (
    select distinct
    apex_item.display_and_save(2,product)||apex_item.hidden(1,env_product_id) PRODUCT,
    APEX_ITEM.SELECT_LIST_FROM_QUERY(3,decode(product, 'HTTP Server' , :p311_current_versions, version), 'SELECT distinct version d, version r FROM ebs_tech_stack where
    product ='''||PRODUCT||'''',
    decode(PRODUCT, 'HTTP Server' ,'multiple="multiple" style="width:170px"','style="width:170px"'),
    'NO') as version
    from ebs_environment_tech_stack
    where environment_id = :p311_umgebung_id) a order by a.product
    If anyone can help me figure out how to set the current values correctly I'd be really grateful!!
    Thanks in advance,
    Jean

    Jean,
    I don't think this is possible using the apex_item package. The select_list_from_query function accepts only a single value for the second parameter.
    Scott

  • Problem writing a sql query for a select list based on a static LOV

    Hi,
    I have the following table...
    VALIDATIONS
    ID          Number     (PK)
    APP_ID          Number     
    REQUESTED     Date          
    APPROVED     Date          
    VALID_TIL     Date
    DEPT_ID          Number     (FK)
    I have a search form with the following field item variables...
    P11_DEPT_ID (select list based on dynamic LOV from depts table)
    P11_VALID (select list based on static Yes/No LOV)
    A report on the columns of the Validations table is shown based on the values in the search form. So far, my sql query for the report is...
    SELECT v.APP_ID,
    v.REQUESTED,
    v.APPROVED,
    v.VALID_TIL,
    d.DEPT
    FROM DEPTS d, VALIDATIONS v
    WHERE d.DEPT_ID = v.DEPT_ID(+)
    AND (d.DEPT_ID = :P11_DEPT_ID OR :P11_DEPT_ID = -1)
    This query works so far. My problem is that I don't know how to do a search based on the P11_VALID item - if 'yes' is selected, then the VALID_TIL date is still valid. If 'no' is selected then the VALID_TIL date has passed.
    Can anyone help me to extend my query to include this situation?
    Thanks.

    Hello !
    Let's have a look at my example:create table test
    id        number
    ,valid_til date
    insert into test values( 1, sysdate-3 );
    insert into test values( 2, sysdate-2 );
    insert into test values( 3, sysdate-1 );
    insert into test values( 4, sysdate );
    insert into test values( 5, sysdate+1 );
    insert into test values( 6, sysdate+2 );
    commit;
    select * from test;
    def til=yes
    select *
      from test
      where decode(sign(trunc(valid_til)-trunc(sysdate)),1,1,0,1,-1)
           =decode('&til','yes',1,-1);
    def til=no
    select *                                                                               
      from test                                                                            
      where decode(sign(trunc(valid_til)-trunc(sysdate)),1,1,0,1,-1)
           =decode('&til','yes',1,-1);  
    drop table test;  It's working fine, I've tested it.
    The above changes to my first idea I did because of time portion of the DATE datatype in Oracle and therefore the wrong result for today.
    For understandings:
    1.) TRUNC removes the time part of DATE
    2.) The difference of to date-values is the number of days between.
    3.) SIGN is the mathematical function and gives -1,0 or +1 according to an negative, zero or positiv argument.
    4.) DECODE is like an IF.
    Inspect your LOV for the returning values. According to my example they shoul be 'yes' and 'no'. If your values are different, you may have to modify the DECODE.
    Good luck,
    Heinz

  • SQL Query based BI Pub report - Taking too long to produce the output

    Hi All,
    I was trying to produce a BI Publisher based report through enterprise edition of BI Publisher 10.1.3.4
    Its a sql query based report and it has around 20 columns and it has around 1 lakh records.
    The query actually takes only 2 seconds to execute in the database but when we execute from BI Publisher it takes a long time and also it times out most of the time
    Is there something I am missing in the configuration options ?
    Thanks
    Shasi

    I am facing the same problem as well. I am using the Publisher Web service API to run a report with 1 Million records. This report is configured to use OBIEE. It takes a lot of time to generate the report ( around 30 Mins) and even though OBIEE generates the data, my web service client either timesout. Even after increasing the timeout, a 500 internal server error is thrown . Does anyone know of a solution to this.
    Thanks

Maybe you are looking for

  • 10.3.9 - 10.4 Migration failed! Server lost! - How to set DHCP info?

    Today we tried to migrate our Xserve from 10.3.9 to 10.4 We've chosen to start the update from a PowerBook and attached our Xserve in FireWire Target Mode. Update/Install ran smoothly, BUT ON RESTART WE LOST CONTACT TO OUR XSERVE In system.log it say

  • Unit of measurment  in chinese

    dear Friends, I am presently implementing SAP4.7 in china and have an issue in UOM. Whenever an transaction is done in chinese for materials with UOM as SET, the system issues an error as below: <b>"Unit of measure SET not defined for language ZH Mes

  • Macbook pro numbers applying a formula to all rows

    macbook pro, numbers: applying a formula to all rows... I am trying to apply the same formula to successive row in a spreadsheet that I am using...how do I go about this?

  • Syntax error in GP_ERR_RSDTPERR, row 198 (- long text)

    Hi Experts, We are getting this error while running DTP for master data." Syntax error in GP_ERR_RSDTPERR, row 198 (-> long text)". Actually i have loading master data for an compunding info object. Pls help me how to resolve this. Thanks & Regards S

  • Tm works fine here's feedback

    This is great. I take it that there was no way around the issues with reformatting drives etc. That would be the first thing to fix, make it work with say, the iomega I bought right out of the box, not after a good flail with reformatting etc. What a