Defaulting Null Values in an outer join to the last joined row's values.

I have a situation where I need to fill in the missing values from an outer join with the last values returned by the join.
The query is based on a date table, an organization table and a transaction table.
SELECT D.DATE_ID, O.ORG_ID, T.VALUE
FROM D_ORGANIZATION O, D_DATE D, F_TRANSACTION T
WHERE D.DATE_ID = T.DATE_ID(+)
AND T.ORG_ID = O.ORG_ID(+)
AND O.ORG_NAME = '&NAME'[
AND D.THE_DATE >= ADD_MONTHS( TO_DATE( '&&PERIOD_DATE', 'DD-MON-YYYY' ), -23 )
AND D.THE_DATE <= ADD_MONTHS( TO_DATE( '&&PERIOD_DATE', 'DD-MON-YYYY' ), 24 )
So the query will return all dates in the 4 year period, and where transactions exist the relevent value.
DATE_ID ORG_ID VALUE
38291     2 99.8
38321     2 45.1
38352     
38383     
38411     
What I need to happen is:
DATE_ID ORG_ID VALUE
38291     2 99.8
38321     2 45.1
38352     2 45.1     
38383 2 45.1
38411     2 45.1
Lag appears to be of no use because it will only pick up the last genuine value, so using
NVL(T.VALUE, LAG(T.VALUE,1) OVER ( .... )
Gives:
ATE_ID ORG_ID VALUE
38291     2 99.8
38321     2 45.1
38352     2 45.1     
38383
38411     
The length of the data gap can vary as constituent organisations don't all return their data at the same time, and there may be intermediate dates where no data is returned , but the value needs to be calculated.
What's going on here is that a gaph is being generated where the tool requires data points to plot the line, once the real data ends a bespoke trend calculations takes over based on the last value returned. I do not have access to the data warehousing options so a solution that doen't need them would be handy, but if not then options can be purchased.
The tool can't use PL/SQL, but is perhaps a bespoke function in order?

To do this wouldn't you need to know the data in advance? The real source table had 1800 organisations and 8,000,000 transactions.
I Tried this as well, creating a pl/sql package as follows.
create or replace PACKAGE stack AS
TYPE gnt_push_numbers IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
TYPE gvt_push_varchars IS TABLE OF VARCHAR(1000) INDEX BY PLS_INTEGER;
gna_push_numbers gnt_push_numbers;
gva_push_varchars gvt_push_varchars;
FUNCTION PUSH ( pn_push_var NUMBER, pn_offset NUMBER) RETURN NUMBER DETERMINISTIC;
FUNCTION PUSH ( pv_push_var VARCHAR, pn_offset NUMBER) RETURN VARCHAR DETERMINISTIC;
FUNCTION POP_NUM ( pn_offset NUMBER) RETURN NUMBER DETERMINISTIC;
FUNCTION POP_VAR ( pn_offset NUMBER) RETURN VARCHAR DETERMINISTIC;
END stack;
CREATE OR REPLACE
PACKAGE BODY "STACK" AS
FUNCTION push(pn_push_var NUMBER, pn_offset NUMBER) RETURN NUMBER deterministic IS
BEGIN
gna_push_numbers(pn_offset) := pn_push_var;
RETURN pn_push_var;
END push;
FUNCTION push(pv_push_var VARCHAR, pn_offset NUMBER) RETURN VARCHAR deterministic IS
BEGIN
gva_push_varchars(pn_offset) := pv_push_var;
RETURN pv_push_var;
END push;
FUNCTION pop_num(pn_offset NUMBER) RETURN NUMBER deterministic IS
BEGIN
RETURN gna_push_numbers(pn_offset);
END pop_num;
FUNCTION pop_var(pn_offset NUMBER) RETURN VARCHAR deterministic IS
BEGIN
RETURN gva_push_varchars(pn_offset);
END pop_var;
END stack;
Unfortunately it appears to act before the rows are sorted, so will only work in specialised circumstances, in that you have to ensure the rows have been sorted before the function is used.
SELECT PUSH(COL), POP..(COL)
FROM ( SELECT etc.
Luckily the client decided they didn't want to mix their graphs any more so a more classic approach using a base table select for actuals and then a date table select with a sub-query columns for the projection provided a simple solution.

Similar Messages

  • How to find out which was the last Function Fired in a given schema ..?

    Hi All ,
    Suppose there is a function called track_account (Accnt_id, bank_name ...)
    I have a requirement wherein I need to find out when was the last date when this function was called , by which user and what was the parameter list that was passed .For example i this case - what accountid and bank_name combinations were passed .
    I know the information is stored in one of the V$ tables but am not able to locate the exact table and column that would give me this information .
    Please suggest .
    Edited by: user3481493 on Mar 8, 2010 10:58 PM

    amol_dev wrote:
    Thank you for your reply Brynjar.
    However, I was trying to figure out a way to do this without having to change the calling command line, because due to legacy reasons, it is not possible to change the command line calling the parent applications of this common code.You cannot change the command line, but you can change the applications?
    In main() do this:
    System.setProperty("whoami",(new Throwable().getStackTrace()[0].getClassName()));Elsewhere:
    String whoami = System.getProperty("whoami");

  • HT201441 i just bough a used iphone but looks that it was found and i cant unlock it. its still link to the last user my question is how do i find out who is the last owner so i can unlock it

    i just bough a used iphone but looks that it was found and i cant unlock it. its still link to the last user my question is how do i find out who is the last owner so i can unlock it

    peeweenborre wrote:
    i just bough a used iphone .... its still link to the last user ...
    If you cannot get this information from the seller
    Removing a device from a previous owner’s account
    You need to return the Device for a refund,

  • Need FM to get the last consumption date and value

    Hello Friends,
       i am developing a report for non moving material , i have got the relevant fields from MSEG,MKPF, MCHB, MCH1,,, but i need the last consumption date for that non moving material batch and value (total amount ) of that batch...
    so i need a Function Modules, to get this values .
    Please help me out
    Regards
    Mukesh

    You have to join MSEG and MKPF ( where MKPF has the posting date ) , ( day,month,year ) . You can calculate the month.moreover, also see S031,S032,S033
    else.
    check it at Mseg-lgort, and movement types for the given matnr.
    from there u can find the consumtion according to movement types .
    for particular period carry mblnr from mkpf and check the movement types which r equal to this mblnr and matnr in mseg.
    so u get the all movement types in that period for particular matnr.
    consumtion = issues - receipt.
    hope this helps u

  • Porting out, how will the last bill workout?

    Looking to port out soon. I know my EFT is $320. But not sure of what the final plan charges will be. My bill just posted, and my billing cycle starts on the 3rd of the month. How does Verizon handle the last bill. Is their any prorating? Should I pay this bill or wait for the final bill? Thanks!

    budney, I regret to hear your considering canceling service. Leiko27, thanks for the information,  your correct. If your under contract and you call to request cancellation of service, the cancellation will not occur within the system until the end of your current bill cycle. Your final bill will have your early termination fee listed.
    Additionally, budney I would like to know why your canceling and review any options so that you can stay with our wireless family. I will send you a private message so that we can discuss your account in further detail. We truly do not want to loose you as a customer and want to make sure you are happy with your service. Your important to us and we value you as a customer. 

  • CONNECT BY with a join, keeping the top joined record  for the entire tree?

    Faced with a Groupe TABLE, and a Groupe_Role TABLE, i am trying to get a user's rights FROM Groupe_Role for each and every member in Groupe. However, the user's rights should be the same right as where we entered the tree.
    Here are sample TABLEs, with my attempt at a query, which obviously does not work because the WHERE clause limits the records from the tree.
    WITH
         Groupe
    AS
          SELECT 1 Id, 'cupboards'      Name, NULL     Parent FROM Dual UNION ALL
          SELECT 2 Id, 'book-shelves'      Name, 1     Parent FROM Dual UNION ALL
          SELECT 3 Id, 'maps'           Name, NULL     Parent FROM Dual UNION ALL
          SELECT 4 Id, 'pictures'      Name, 3     Parent FROM Dual UNION ALL
          SELECT 5 Id, 'pegs'           Name, 4     Parent FROM Dual UNION ALL
          SELECT 6 Id, 'jar'           Name, NULL     Parent FROM Dual UNION ALL
          SELECT 7 Id, 'orange marmalade' Name, 6     Parent FROM Dual UNION ALL
          SELECT 8 Id, 'sticks'           Name, NULL     Parent FROM Dual UNION ALL
          SELECT 9 Id, 'dry leaves'      Name, 8     Parent FROM Dual
         Groupe_Role
    AS
          SELECT 1 Groupe, 'Charles'     Member, 'Keeper'     Role FROM Dual UNION ALL
          SELECT 2 Groupe, 'Charles'     Member, 'Player'     Role FROM Dual UNION ALL
          SELECT 3 Groupe, 'Lewis'     Member, 'Keeper'     Role FROM Dual UNION ALL
          SELECT 1 Groupe, 'Alice'     Member, 'Player'     Role FROM Dual UNION ALL
          SELECT 3 Groupe, 'Alice'     Member, 'Player'     Role FROM Dual UNION ALL
          SELECT 6 Groupe, 'Alice'     Member, 'Player'     Role FROM Dual UNION ALL
          SELECT 8 Groupe, 'Alice'     Member, 'Player'     Role FROM Dual
    SELECT
         Groupe.Id,
         Groupe.Name,
         Groupe_Role.Member,
         Groupe_Role.Role
    FROM
         Groupe_Role,
         Groupe
    WHERE
         Groupe.Id = Groupe_Role.Groupe
    CONNECT BY
         Groupe.Parent = PRIOR Groupe.Id
    START WITH
         Groupe.Parent IS NULL
    ORDER BY
         Groupe_Role.Member,
         Groupe_Role.Groupe;The results i am looking for are as follows:
    1 Alice      Player 'cupboards'
    2 Alice      Player 'book-shelves'
    3 Alice      Player 'maps'
    4 Alice      Player 'pictures'
    5 Alice      Player 'pegs'
    6 Alice      Player 'jar'
    7 Alice      Player 'orange marmalade'
    8 Alice      Player 'sticks'
    9 Alice          Player 'dry leaves'
    1 Charles     Keeper 'cupboards'
    2 Charles     Keeper 'book-shelves'
    2 Charles     Player 'book-shelves'
    3 Lewis      Keeper 'maps'
    4 Lewis      Keeper 'pictures'
    5 Lewis      Keeper 'pegs'How would i write such a query?

    It's amazing what a little legwork will do:
    10g: CONNECT_BY_ROOT Id Root_Id,
    9i:     REPLACE(SYS_CONNECT_BY_PATH(DECODE(Level, 1, Id), '~'), '~')
    WITH
         Groupe
    AS
          SELECT 1 Id, 'cupboards'      Name, NULL     Parent FROM Dual UNION ALL
          SELECT 2 Id, 'book-shelves'      Name, 1     Parent FROM Dual UNION ALL
          SELECT 3 Id, 'maps'           Name, NULL     Parent FROM Dual UNION ALL
          SELECT 4 Id, 'pictures'      Name, 3     Parent FROM Dual UNION ALL
          SELECT 5 Id, 'pegs'           Name, 4     Parent FROM Dual UNION ALL
          SELECT 6 Id, 'jar'           Name, NULL     Parent FROM Dual UNION ALL
          SELECT 7 Id, 'orange marmalade' Name, 6     Parent FROM Dual UNION ALL
          SELECT 8 Id, 'sticks'           Name, NULL     Parent FROM Dual UNION ALL
          SELECT 9 Id, 'dry leaves'      Name, 8     Parent FROM Dual
         Groupe_Role
    AS
          SELECT 1 Groupe, 'Charles'     Member, 'Keeper'     Role FROM Dual UNION ALL
          SELECT 2 Groupe, 'Charles'     Member, 'Player'     Role FROM Dual UNION ALL
          SELECT 3 Groupe, 'Lewis'     Member, 'Keeper'     Role FROM Dual UNION ALL
          SELECT 1 Groupe, 'Alice'     Member, 'Player'     Role FROM Dual UNION ALL
          SELECT 3 Groupe, 'Alice'     Member, 'Player'     Role FROM Dual UNION ALL
          SELECT 6 Groupe, 'Alice'     Member, 'Player'     Role FROM Dual UNION ALL
          SELECT 8 Groupe, 'Alice'     Member, 'Player'     Role FROM Dual
    SELECT
         Groupe_Trees.Id,
         Groupe_Trees.Name,
         Groupe_Role.Member,
         Groupe_Role.Role
    FROM
         Groupe_Role,
          SELECT
              --CONNECT_BY_ROOT Id Root_Id,
              REPLACE(SYS_CONNECT_BY_PATH(DECODE(Level, 1, Id), '~'), '~') Root_Id,
              Id,
              Name
          FROM
              Groupe
          CONNECT BY
              Groupe.Parent = PRIOR Groupe.Id
         ) Groupe_Trees
    WHERE
         Groupe_Role.Groupe = Groupe_Trees.Root_Id
    ORDER BY
         Groupe_Role.Member,
         Groupe_Trees.Id;

  • Can i get summary column value of one group appears at the last page once

    Hi,
    I am having one group G_Item.I need the summary column(CS_Total_quantity->source as :cp_quantity) value as Total quantity value of the report andprint it on the last page.How can i get that value?Please advise me.Urgent......Waiting for reply.
    Thank You

    try this...
    put a summery column outside the quey.
    & take sum of "CS_Total_quantity".
    set its reset at property to "report". & print object on "last page".
    hope this 'll work for u.
    Capri...

  • Strip out one of the two duplicate rows

    Hi Guys,
    I wonder if it is possible to strip out of of the duplicate rows to put it into a "duplicates table" and leave the other one in there i.e.
    name id no part
    myrows 1 2 3
    myrows 1 2 3
    thanks,
    metalray
    PS: I heard that in mssql there was a row_over() function that helped with that.

    Well
    A solution would be
    INSERT INTO DUP_TABLE
    SELECT <list of fields> from (
    SELECT <list of fields> , row_number() over (PARTITION BY <list of fields> order by <a field> ) as rn from source_table)
    where rn > 1)
    DELETE FROM SOURCE TABLE WHERE ROWID IN (SELECT ROWID FROM (
    SELECT rowid , row_number() over (PARTITION BY <list of fields> order by <a field> ) as rn from source_table)
    where rn> 1)
    where list of fields is all the fields of your table and a field any field of your table.

  • Re: Porting out, how will the last bill workout?

    @KinquanaH_VZW:
    Please tell how does it bill if the number is already on month to month after years of service? 
    Is it prorated then?
    Does one need to take any action after a confirmed port to a different carrier? (confirmed by the new carrier)
    <Branched to a new discussion.>
    Message was edited by: Verizon Moderator

        Good question huCairs! Whether you are on a month-to-month contract or still within the 2-year contract, the Terms & Conditions of the Customer Agreement (http://bit.ly/Kg6KQP) still apply equally to any contract services. So there is still no proration for ending service, since the account will complete the close at the end of the bill cycle.
    We certainly don't want to lose you as a customer. Please let us know if there's something we can help with that's making you consider porting out.
    Thank you
    JenniferH_VZW
    Please follow us on Twitter @vzwsupport

  • My iPhone 5 has suddenly stopped sending emails. I get the message "Enter the password for the Account account "(null)"". This has only happened since the last update to iOS but hasn't been a problem on my iPad. What is going on?

    IiPhone 5 has stopped sending emails.

    Hello, Taffy12gwen. 
    Thank you for visiting Apple Support Communities.
    Here is an article I would recommend going through when experiencing issues with mail.
    iOS: Troubleshooting Mail
    http://support.apple.com/kb/ts3899
    Cheers,
    Jason H.

  • My ipad battery ran out while verifiying the last update. Now all I see on the screen is the plugin symbol with an arrow and the itunes symbol. Help!

    Help, as above, lost power part way though verifiying last update.
    Now all i see is the plugin symbol with an arrow, and the itunes symbol
    in the middle of a black screen.
    Does anyone have any ideas? I've tried  powering down, with no luck.
    Help, please, or should I just box it up and send to repair center?

    CREEEP wrote:
    Now all i see is the plugin symbol with an arrow, and the itunes symbol in the middle of a black screen.
    1: Connect the device to Your computer and open iTunes.
    2: If the device appears in iTunes, select and click Restore on the Summary pane.
    Restoring  >  http://support.apple.com/kb/HT1414
    3: If the device doesn't appear in iTunes, try using the Steps in this article to force the device into Recovery Mode.
    Make sure you have the Current Version of iTunes Installed on your computer
    iTunes free download from www.itunes.com/download
    Note on Recovery Mode.
    You may need to try this More than Once... Be sure to Follow ALL the Steps...
    After you have Recovered your Device...
    Re-Sync your Content or Restore from the most Recent Backup...
    Restore from Backup  >  http://support.apple.com/kb/ht1766

  • How to get values of selection screen fields in the POV event

    I have two radio buttons r1,r2 and a field file_name on  selection screen.
    I have written At selection screen on value-request for the field file_name. Based on the selection of radio buttons I have to display different screens when f4 for field_name is pressed.
    Unfortunately the values of r1 or r2 are not populated in the AT selection screen on value-request event.
    Can any one tell me if there is a way to obtain the values of r1 or r2 in the AT selection  screen on value-request event.

    Hi..
    Try out this.
    REPORT  ZH_TEST4                                .
    CONSTANTS : c_x                TYPE char01 VALUE 'X',
                c_rg1(4)        TYPE c      VALUE 'RG1',
                c_gr2(3)        TYPE c      VALUE 'GR2',
                c_gr3(3)        TYPE c      VALUE 'GR3',
                c_zero          TYPE n      VALUE '0',
                c_neg(2)        TYPE c      VALUE '-1'.
    data: w_sscrfields_ucomm1   TYPE sscrfields-ucomm.
    SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    PARAMETERS       : p_back   RADIOBUTTON GROUP rg1
                                     USER-COMMAND pc,
                       p_fore   RADIOBUTTON GROUP rg1
                                          DEFAULT 'X'.
    SELECTION-SCREEN : END OF BLOCK blk1.
    SELECTION-SCREEN : BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
    PARAMETERS : p_phif LIKE rlgrap-filename  MODIF ID gr2,
                 p_ahif LIKE rlgrap-filename  MODIF ID gr3.
    SELECTION-SCREEN : END OF BLOCK blk2.
    AT SELECTION-SCREEN OUTPUT.
      IF p_fore EQ c_x.
        w_sscrfields_ucomm1 = c_rg1.
      ELSE.
        w_sscrfields_ucomm1 = space.
      ENDIF.
      LOOP AT SCREEN.
        IF w_sscrfields_ucomm1 EQ space.
          IF screen-group1 = c_gr2.
            screen-active = c_zero.
          ENDIF.
        ELSE.
          IF screen-group1 = c_gr3.
            screen-active = c_zero.
          ENDIF.
        ENDIF.
        MODIFY SCREEN.
      ENDLOOP.
    also try out function module POPUP_WITH_TABLE_DISPLAY.
    Plz reward points if this helps by clicking on star!1
    Good Luck!!
    Cheers,
    Rajeev

  • To find out the last row that is updated in a View Object

    Hi OAF Gurus,
    I have requirement like,
    I have to find out the last row that is updated on a particular View Object and I have send a mail to the users about the change.
    JegSAMassMobVOImpl vo = getJegSAMassMobVO1();
    JegSAMassMobVO is the View Object Name and it displays certain rows that has already been added to the VO in the Page.
    Now the issue is when a user updates a particular row,I have to find which row gets updated and have to send a email to that particular employee about the change.
    Just want to know,how to find out the last updated row in a particular VO.
    Any Help would be appreciated as this a immediate requirement.
    Regards,
    Magesh.M.K.
    Edited by: user1393742 on May 4, 2011 1:06 AM

    Hi Magesh
    It shoud be a Advanced table ,so when user will update the row ,the specific row will fire the PPR and on that event u can capture the row using row reference ,this is the sample code below
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processFormRequest(pageContext, webBean); OAApplicationModule am =
    (OAApplicationModule)pageContext.getApplicationModule(webBean);
    String event = pageContext.getParameter("event");
    if ("<ItemPPREventName>").equals(event))
    // Get the identifier of the PPR event source row
    String rowReference =
    pageContext.getParameter(OAWebBeanConstants.EVENT_SOURCE_ROW_REFERENCE);
    Serializable[] parameters = { rowReference };
    // Pass the rowReference to a "handler" method in the application module.
    262
    am.invokeMethod("<handleSomeEvent>", parameters);
    In your application module's "handler" method, add the following code to access the source row:
    OARow row = (OARow)findRowByRef(rowReference);
    if (row != null)
    Thanks
    Pratap

  • Problem in universe while joining as the primary key is NUMBER

    Hi,
    I'm trying to join TEST.SUMMARY.NUMBER to TEST.RESPONSE.FOREIGN_KEY. The problem arises from the first of these, as the primary key is in a column NUMBER. Stupid? Definitely. Rename? Not an option.
    I think NUMBER is seen as a magic word (type), and once parsing (for example in "edit join", I get the message "Exception: DBD, ORA-01747: invalid user.table.column, table.column, or column specification State: N/A" .
    Normally putting " around the word would do the trick ("NUMBER"), but is seems universe designer removes those during the parsing (?). I come to this conclusion, because if I choose the join line from the graphical menu, and then write to the function line TEST.SUMMARY."NUMBER"=TEST.RESPONSE.FOREIGN_KEY (and press enter), the " are removed. (To get the NUMBER's to the report is good, though, by creating a variable with TEST.SUMMARY."NUMBER")
    The database is oracle, and universe is on BusinessObjecs XI 3.1.  I've tried to join in the edit join, create a derived table and use ANSI92. No good so far. I also tried to join the fields on report (WebI), but the result was always too many or not enough data from one of the tables. Merging dimensions leads to other problems. I was checking on JOIN_BY_SQL as well as PARSE_SELECT_IN_JOIN in universe parameters, but at glance I didn't find how to solve this with them.
    Any ways to force the join, or achieve the data from the both tables in one report table otherwise?

    Well, I managed to sort this out somehow by using custom SQL in the Web Intelligence report, and joining the tables there with
    LEFT JOIN TEST.RESPONSE
    ON TEST.SUMMARY."NUMBER"=TEST.RESPONSE.FOREIGN_KEY
    Smells like duck tape, but it's  working at least somehow. I guess the custom SQL is passed to some lower level, and so the universe-automatic-whatever doesn't handle it in the fly.
    Any other ideas?

  • Is it possible to maintain the last AO value after the DAQmx task is done on device DAQ USB-6341 ?

    Hi all,
    I use the device DAQ USB-6341 to generate the desired voltage waveform by the "finite samples" sample mode.
    I notice that the channel resets to zero volts after the DAQmx task is done and the DAQ USB-6341 does not have 
    the property AO.idleOutputBehavior to select "Maintain Existing Value".
    How can I maintain the last AO value after the DAQmx task is done on device DAQ USB-6341 ?
    Thanks.
    Godel

    How many computers do you have in the network?
    What is the IP address and default gateway number on your computer?
    In order to connect to the wireless network, WVC80N should get valid IP address from the access point.
    If the access point has capacity to assign a private IP address to the computers and devices then I think you can use WVC80N.

Maybe you are looking for

  • I cannot select "sync iPod" on my Windows 7 computer

    I have an ipod classic and now that I hvew a new computer it will not recogniz that I have an ipod plugged in!! Help??

  • IPhone stuck in recovery mode after failed update.

    Hi, I have a bad situation here... My iPhone 5 got stuck in recovery mode after I tried to update to iOS 7.1.1 from 7.0.4 and it failed (error code 6). If this was my iPod touch I would just restore it because all I have is music, but this iPhone has

  • Cast Documented Behaviour?

    Take a look at the following sample. In the last statement, I use a CAST and understand why it only shows the first letter. But why does it do the same for the other column in which I don't use the CAST? SQL> select *   2    from v$version   3  / BAN

  • Inventory Key Flex Fields

    There is a KFF in the Inventory module called 'Sales Order'. Does anyone know on which form can I find this KFF? Thank you SK

  • How can I get Top Sites to open full screen?

    How can I get Top Sites to open full screen?