Return two values for one site in single query

Oracle 10g on Solaris 10
data:
value integer
date timestamp
This query works as is:
WITH vals AS
     (SELECT start_date_time,
          value
     FROM     r_base a,
          hdb_site_datatype b,
          hdb_site c,
          hdb_datatype d
     WHERE     a.site_datatype_id = b.site_datatype_id
     AND     a.interval = 'day'
     AND     b.site_id = c.site_id
     AND     c.site_common_name = 'CABALLO'
     AND     b.datatype_id = d.datatype_id
     AND     d.datatype_common_name = 'pool elevation'
     AND     a.start_date_time > a.start_date_time - 367)
     SELECT x.start_date_time,
          x.VALUE,
          y.start_date_time,
          y.VALUE AS valuem1w,
          z.start_date_time,
          z.VALUE AS valuem1dm1y
     FROM     vals x,
          vals y,
          vals z
     WHERE     y.start_date_time(+) = x.start_date_time - 7
     AND     z.start_date_time(+) = ADD_MONTHS (x.start_date_time-1,-12)
     AND     x.start_date_time = TO_DATE('07-JAN-2008','DD-MON-YYYY');
and this query works:
WITH vals AS
     (SELECT start_date_time,
          value
     FROM     r_base a,
          hdb_site_datatype b,
          hdb_site c,
          hdb_datatype d
     WHERE     a.site_datatype_id = b.site_datatype_id
     AND     a.interval = 'day'
     AND     b.site_id = c.site_id
     AND     c.site_common_name = 'CABALLO'
     AND     b.datatype_id = d.datatype_id
     AND     d.datatype_common_name = 'storage'
     AND     a.start_date_time > a.start_date_time - 367)
     SELECT x.start_date_time,
          x.VALUE,
          y.start_date_time,
          y.VALUE AS valuem1w,
          z.start_date_time,
          z.VALUE AS valuem1dm1y
     FROM     vals x,
          vals y,
          vals z
     WHERE     y.start_date_time(+) = x.start_date_time - 7
     AND     z.start_date_time(+) = ADD_MONTHS (x.start_date_time-1,-12)
     AND     x.start_date_time = TO_DATE('07-JAN-2008','DD-MON-YYYY');
I need it to return storage and pool elevation in a single query instead of two queries.
The results should be:
current day, elevation_value; current day minus 1 week, elevation_value; current day minus 1 day minus 1 year, elevation_value; current day, storage_value; current day minus 1 week, storage_value; current day minus 1 day minus 1 year, storage_value
Thanks
Very, very much appreciate if you can show me how to do this..

something like this, perhaps? (untested, as I don't have your data):
WITH date_param as (select TO_DATE('07-JAN-2008','DD-MON-YYYY') p_date from dual),
SELECT max(nvl(case when d.datatype_common_name = 'pool elevation'
                         and a.start_date_time = p_date then value
               end)) elevation_curr_day_val,
       max(nvl(case when d.datatype_common_name = 'pool elevation'
                         and a.start_date_time = p_date-7 then value
               end)) elevation_last_week_val,
       max(nvl(case when d.datatype_common_name = 'pool elevation'
                         and a.start_date_time = add_months(p_date-1, -12) then value
               end)) elevation_last_year_val,
       max(nvl(case when d.datatype_common_name = 'storage'
                         and a.start_date_time = p_date then value
               end)) storage_curr_day_val,
       max(nvl(case when d.datatype_common_name = 'storage'
                         and a.start_date_time = p_date-7 then value
               end)) storage_last_week_val,
       max(nvl(case when d.datatype_common_name = 'storage'
                         and a.start_date_time = add_months(p_date-1, -12) then value
               end)) storage_last_year_val
FROM r_base a,
      hdb_site_datatype b,
      hdb_site c,
      hdb_datatype d
WHERE a.site_datatype_id = b.site_datatype_id
AND a.interval = 'day'
AND b.site_id = c.site_id
AND c.site_common_name = 'CABALLO'
AND b.datatype_id = d.datatype_id
AND d.datatype_common_name in ('pool elevation', 'storage')
AND a.start_date_time in (p_date, p_date-7, add_months(p_date-1, -12));

Similar Messages

  • Can we maintain two values for one material a plant without split valuation

    Hello Guru's,
    We have a situation, we use MOVING AVERAGE PRICE in accounting view 1. Without split valuation.
    The actual issue is, we receive, damaged material from a customer with a "0" value, and we send the material as it is, to a vendor with a "0" value.
    The vendor, sends us back the repaired material with a value, say "10" (and this keeps changing).
    Is it possible, to have Non Valuated Stock and Valuated Stock within the same Plant, for Material "A".
    And it shouldn't affect the MAP. Also, we don't want to have Split Valuation.
    Please help.
    Kashi

    if i am getting your scenrio correctly then i will suggets u to maintian  the material master with moving avreage price control indicator then
    case1> gr from customer at o rs
    use the tcode mb1c and movement type 511
    as it is evaluated at MAP hence only material document genrated no accounting document
    well tried to realize your scenerio but it is not possible to do that
    as MAP is going to get effected as a result of valuated good recipet
    u need to go for separate material code then transfer good from non valuated to valuated one using tcode mb1b and movement type 309 or use split valuation

  • Multiple values for one variable?

    I've created my first set of variables (using Form Properties>Variables), tweeked some XML sourcecode  and they're working .
    What I'm now trying to figure out is how to have one variable that has 2 values that pop up in 2 different text fields.
    Simple form at this point:
    Item, Model and Service Tag.
    The user selects the item from the drop down list and the Service Tag field is autopopulated from the variables I set.
    How do I get the Model to appear based on the Item selection?
    I tried putting the two values for one variable together but both values appear in the same field.
    Variable info that works: Scan (variable) = MC3090BT (value)
    I also need this particular variable to = Handheld scanner (try to ignore the redundancy).
    I attempted to make MC3090BT as it's own variable with Handheld scanner as it's value, and add to the code below but it didn't work.
    Here's some of the code if it helps:
    <event activity="change" name="event__change">
                   <script contentType="application/x-javascript">if(xfa.event.newText == "Handheld scanner"){
        servicetag.rawValue = scan.value;
    }else if(xfa.event.newText == "Latitude X1"){
        servicetag.rawValue = X1.value;

    Hi, I am trying to do the same thing..passing multiple values to receiving query variable through RRI.  Right now if I assign a query variable of type multiple single values it does not take any value.  It works only if I assign variable of type Single Value.
    In my assignment details the sender query has Generic for type and * for selection type. 
    If any one knows how to pass multiple values to receiving RRI query,  please give the details.
    Thanks

  • Error that "specify a value for variable posting period (single value entry

    hi
    My query is running testing fine in RSECADMIN under some username..but when i try and open it using analyzer (under same username) it gives me error that "specify a value for variable posting period (single value entry, mandatry)" it does'nt even asks to enter variable values and gives this error message.
    However the same query appears to be working fine under different username.
    plz advise.

    Hi Abhinav,
    Just do one thing compare the Roles of two different users for which Query is getting executed and not.
    Check the Object S_RFC.
    Compare the Objects detail for Both the Users.
    Please Assign points if useful.
    Regards,
    Rajdeep.

  • How do I return two values from a stored procedure into an "Execute SQL Task" within SQL Server 2008 R2

    Hi,
    How do I return two values from a
    stored procedure into an "Execute SQL Task" please? Each of these two values need to be populated into an SSIS variable for later processing, e.g. StartDate and EndDate.
    Thinking about stored procedure output parameters for example. Is there anything special I need to bear in mind to ensure that the SSIS variables are populated with the updated stored procedure output parameter values?
    Something like ?
    CREATE PROCEDURE [etl].[ConvertPeriodToStartAndEndDate]
    @intPeriod INT,
    @strPeriod_Length NVARCHAR(1),
    @dtStart NVARCHAR(8) OUTPUT,
    @dtEnd NVARCHAR(8) OUTPUT
    AS
    then within the SSIS component; -
    Kind Regards,
    Kieran. 
    Kieran Patrick Wood http://www.innovativebusinessintelligence.com http://uk.linkedin.com/in/kieranpatrickwood http://kieranwood.wordpress.com/

    Below execute statement should work along the parameter mapping which you have provided. Also try specifying the parameter size property as default.
    Exec [etl].[ConvertPeriodToStartAndEndDate] ?,?,? output, ? output
    Add a script task to check ssis variables values using,
    Msgbox(Dts.Variables("User::strExtractStartDate").Value)
    Do not forget to add the property "readOnlyVariables" as strExtractStartDate variable to check for only one variable.
    Regards, RSingh

  • Can I use a domain for one site and mobile me for a different site?

    Can I use a domain for one site and mobile me for a different site?
    I have two sites, I would like to have up and I would like to do one through a domain and one through mobileme is this possible?

    Yes you can. You can use the CNAME method of forwarding for the first site (the top site in iWeb) and use the MMe URL for your account for the other site: http://web.me.com/YourAccount_Name/SiteName/
    OT

  • Two prices for one material in sales order according condition type

    Hi,
    I configure the condition type according to following condition record:
    Plant/ Sales Organization/ Distribution channel/ Material / Customer
    (because system should calculate two prices for one material in two plants)
    In the sales order screen, when user firstly select material , quantity, plant ,  system calculate the related price correctly but if user select the material and quantity and enter and after that select the plant, system will show the error message in pricing procedure and to have a price for material, user should update the price in the price condition in sales order.
    It is so difficult for user to update one by one, because there are several sales orders which need to update.
    Is it any way to solve this problem?
    Thanks,

    > In the sales order screen, when user firstly select material , quantity, plant ,  system calculate the related price correctly but if user select the material and quantity and enter and after that select the plant, system will show the error message in pricing
    Hi,
    Why to let the user press Enter button before entering plant value Obviously, system will give error, because it doesnt get all the required value based on which you have maintained condition records.
    Ask the user to enter all the value at item level otherwise you will have go for the option that you are doing currently.
    It is said prevention is better than cure
    Hope you get some inputs
    regards,
    Sagar

  • Multiple Values For one Condition in Choose From List

    I have used one Business Partner Choose From List in my form but i want to give condition in that choose from list on GroupCode .But the condition will have multiple values like 100,102,104 then how i will write the code to incorporate multiple values for one single condition.

    Hi,
    Check this thread
    How to set a Multiple condition in a single CFL
    Hope that helps,
    Vasu Natari.

  • Two address for one company code

    Hi SAPians,
    I have a doubt in maintaining company address for Invoice output!
    Is it possible to maintain two Address for one company code?
    Like if XYZ company code and say it has has two customers AB and CD.
    Then if i want to maintain Company address on print layout for invoice Different to each. how can i achieve it.
    If yes, please through light on it.
    Regards,
    Romesh

    Hi ,
    As far i know it is not possible to have two different address for the same company code.As table can hold only single unique data.
    As far as the above answer is concerned, we use International version fo Customers not for Company Codes.
    Hope it helps.
    Thanks and Regards
    Rohit.

  • Maintaining two values for upper & lower specification for a MIC

    Hi gurus,
    My client requirement is that they want to maintain two values for upper specification and lower specification for a quantitative characteristic.
    For eg. Master inspection characteristic is carbon %
    & for this characteristic they want to maintain values as follows
    lower specification:0.00   upper specification:0.32
    lower specification:0.37   upper specification:0.60
    The requirement is that both these limits should be maintained for the same MIC and system should not allow values between 0.32-0.37
    Is this possible in standard scenario.If possible pls. provide me the solution.
    Thanks in advance.

    No, not possible in standard SAP.  A test can only have one set of limts.
    What you describe sounds more like specs anyway rather then test limits. 
    Your client isn't maintaining specs for materials in MIC's are they?  This would be the least desirable method and not really the way SAP designed it to be.
    Craig

  • Two billing for one sales order for same customer

    Dear All ,
    I have a requirement of posting a two billings for one sales order.
    One is for Sales and another is for commission...
    Entry could be
    Sales Entry - Db Customer
                        Cr  Sales
    Commission entry could be
    Db - Cusomter
    Cr- Sales commission income account (P/L)
    We are having third party sales scenario , In this case billing is MIRO dependent.
    Once the miro is done then only billing is possible ...
    Could you please advise on that ..
    Regards,
    Sukh

    Dear Ratish,
    Thanks for yr reply.
    I already did that but it is not serving business purpose.
    Comm payment  - comes diff time than sales payment.
    so ,I will post one entry customer will get hit with total amount Sales + commission
    like below
    Let say 10, 000 is the sales value and 500 is the commission
    So , This entry will get posted
    Customer Db- 10,500
    Sales Cr- 10,000
    Comm Income Cr- 500
    But, As I said sales amt will be paid before so We need to clear it partially and some time customer pays also diff amount due to some defect.
    So, We wont be knowing for which case we have or havnet received the payment against commission.
    As , Customer account is got hit with total amount( Sales+ Comm..value).
    Pls advise how to solve this.
    Regards,
    Sukh

  • I Need to Return Two values or more from Function, Is this possible?

    Below is the offending query, I am trying to pass v_bu and v_po to this function, and after validations then return v_count and v_action is this possible in a function? I am having problem returning two values.
    see below code
    function po_edi_func(v_bu purchase_order.business_unit_id%type,
         v_po purchase_order.purchase_order_number%type)
         return number as pragma autonomous_transaction;
         v_count               number;
         v_ctdel               number;
         v_action          varchar2(1);
    begin
    select count(*)
    into v_count
    from sewn.purchase_order
    where business_unit_id=v_bu
    and purchase_order_number =v_po;
    if v_count > 0 then
         select count(*)
         into v_ctdel
         from sewn.purchase_order
         where business_unit_id=v_bu
    and purchase_order_number =v_po
         and purc_orde_status = 1;
         if v_count <> v_ctdel then -- ALl PO's Cancelled--
         v_action := 'U'; -- - NOT ALL PO DELETED --
         else
         v_action := 'D'; -- DELETED ALL PO--
         end if;
    else
         v_action := 'I';-- New PO INSERT--
    end if;
    commit;
    return v_count;
    end;

    Paul,
    This is becoming a nightmare to me, can you look at the below and tell me where I am having a problem
    This is the Function below
    CREATE OR REPLACE function po_edi_func(v_bu sewn.purchase_order.business_unit_id%type,
         v_po sewn.purchase_order.purchase_order_number%type,v_action_out OUT VARCHAR2)
         return number as pragma autonomous_transaction;
         v_count               number;
         v_ctdel               number;
         v_action          varchar2(1);
    begin
    select count(*)
    into v_count
    from sewn.purchase_order
    where business_unit_id=v_bu
    and purchase_order_number =v_po;
    if v_count > 0 then
         select count(*)
         into v_ctdel
         from sewn.purchase_order
         where business_unit_id=v_bu
    and purchase_order_number =v_po
         and purc_orde_status = 1;
         if v_count <> v_ctdel then -- ALl PO's Cancelled--
         v_action := 'U'; -- - NOT ALL PO DELETED --
         else
         v_action := 'D'; -- DELETED ALL PO--
         end if;
    else
         v_action := 'I';-- New PO INSERT--
    end if;
    commit;
    v_action_out := (lpad(v_count,8,'0')||lpad(v_action,1,' '));
    return v_action_out;
    end;
    and this is how I am calling it from my trigger which has to pass the v_bu and v_po values to be used in extracting data and returning the records
    see below
    if po_edi_func(v_bu,v_po) <> '' then;
    v_count:= (substr(v_action,1,8));
    v_action := substr(v_actione,9,1);
    else
    v_count:=0;
    v_action := 'I';
    end if;
    I need the extracted values of v_count and v_action for my app to reset some values

  • Two titles for one screen

    Hi Everyone,
    Is it possible to give two titles for one dialog screen.
    Based on a grid i perform centain things where the user has to enter the values in the dialog screen.
    To this screen i want to title based on the which grid it is. Is it possible to do.
    Can anyone help me on this.
    Thanks,
    Prabs.

    when you define the title bar (to be used with set title bar)
    enter the text with place holders like below.
    & & my &
    later in your program you can supply text for & using set title bar.
    set titlebar 'MYTITLE' with 'This' 'is' 'test' .
    This would produce title bar as
    This is my test
    set titlebar 'MYTITLE' with 'Where' 'is' 'Title' .
    This would produce title bar as
    Where is my Title.
    Hope this is clear.
    Regards
    Raja

  • How to create two respone for one request

    Hi
    is there any way for us to create two response for one request
    the scenario is as below
    1. user click on update button for particular record in the datatable (
    after its get updated and status get updated = 'UPDATED' it will remove the object from ObjectListDataProvider and clear the tablePhaseListener ).
    2. After it gets updated successfuly , i want to prompt the user with generateExcel function which using response.getOutputStream() using Apache POI.
    How can we combine 1 and 2 together
    Here what i have tried and didnt work
    1. i tried to put the generateExcel function in destroy() method after page is rendered but it gives me Exception
    2. i tried to put the generateExcel function in prerender() method
    but the page will only execute the generateExcel function
    - the data still get updated to the database but it doesnt refresh the page ( i meant the removing object and tablephaseListener.clear() doesnt work )
    3 . i tried to put generateExcel Function after it process the data
    public String updateData()
           //update data
           if(success){
                // prompt user to save excell sheet
            return null;
         }This one also doesnt work and gives the same behaviour as number 2
    The Prompt to save excel sheet still gets popped up
    but the page just doesnt get refreshed
    Thanks
    is anybody know the workaround?

    yea i did set some alert message and clear the table by calling
    provider.removeRow and commitChanges
    it just doesnt reflected in the page that we see
    by actually is already removing the row from the provider
    Thanks

  • Two invoices for one sales order

    I want to create two invoices for one sales order
    Scenario is like to create sales order for value of 100 $, and I want to send order reference billing after saving the sales order for 10% of order amount
    I would say 10% of 100 $
    And after delivery I want to issue a invoice for 90 %( rest of the amount) which is delivery relevant invoice.
    Both invoices will be relevant of accounting.
    Would any body suggest this, how it would be mapped it in to SAP.

    Hi Suresh,
    It is possible in Partial billing. Maintain the Billing plan and create a plan with the inputs as u specified.
    Go to IMG-SD-Billing-Billing plan.   Do ur own configuration for Billing plan.
    Now in Sales document creation mode....header details-Billing plan, U block the billing schedules and as per ur requirement , remove the billing block and create billing document.
    If u configured Account detrmination procedure, U wld get the accounting document wrt billing document.
    Hope this wld help U.
    Regards,
    Praveen

Maybe you are looking for