How to query most recent rows based on datetimestamp

Hi
Using the query below I am generating an output of machines (facility_code) but at present I am getting the same machine reported several times due to there being more than one instance of that machine in the table. What differs these mulitple entries is the start date field so based on that field I wish to pull only the most recent entry for each facility code. I would like to display the output of the query below on this forum to clarify my ramblings but the only way seems to via a text editor which does not allow for displaying formatted data and thus is is nigh on impossible to read/understand here. Any suggestions?
SELECT F_FACILITY_CODE,
CASE
when JOB_DATE_ACT_START < TO_DATE('26-06-2000 07:00:00', 'DD-MM-YYYY HH24:MI:SS') then SCH_DATE_DUE
else JOB_DATE_ACT_START
END StartDate
,FS_STATE,
CASE
when JOB_ACTIVITY_CAUSE like ' ' and SA_ACTIVITY_CAUSE like ' ' then JREQ_REQ_CODE2
when JOB_ACTIVITY_CAUSE LIKE ' ' and SA_ACTIVITY_CAUSE <> ' ' then SA_ACTIVITY_CAUSE
else JOB_ACTIVITY_CAUSE
END Cause
,JREQ_ORIGINATOR,
CASE
when JOB_JOB_TITLE like ' ' and JREQ_JOB_TITLE like ' ' then SA_JOB_TITLE
when JOB_JOB_TITLE LIKE ' ' and JREQ_JOB_TITLE <> ' ' then JREQ_JOB_TITLE
else JOB_JOB_TITLE
END Comments
FROM ALL_JOBS_VIEW, FACILITY_REFERENCES
WHERE
ALL_JOBS_VIEW.SCH_FACILITY_CODE = FACILITY_REFERENCES.FACILITY_CODE AND
ALL_JOBS_VIEW.JOB_JOB_STATUS <> 'CL' AND
FACILITY_REFERENCES.REF_PROMPT = '72 WAFER AREA' AND
FACILITY_REFERENCES.REF_DATA ='varArea'
ORDER BY
"FACILITY_REFERENCES"."REF_DATA" ASC
Thanks a mil
Emma

Even.. without subquery
sql>select * from mac;
MC ST_DT STATUS
ASM_51  25-JAN-07  IDLE 
ASM_51  18-JAN-07  IDLE 
ASM_51  10-JAN-07  IDLE 
ECO_53  02-NOV-06  PROD 
ECO_53  23-NOV-06  PROD 
ECO_53  25-NOV-06  PROD 
sql>
select min(mc) keep(dense_rank first order by st_dt desc) mc,
       max(st_dt) dt,
       min(status) keep(dense_rank first order by st_dt desc) status
from mac
group by mc;
MC DT STATUS
ASM_51  25-JAN-07  IDLE 
ECO_53  25-NOV-06  PROD
jeneesh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • How to return only the most recent row?

    Hi guys,
    I have a question which I am hoping is not too difficult but I just am not sure how to do it. I need to run a query on a table which may bring back multiple rows for my criteria, however I only want to bring back 1 of these multiple rows and the one I want to bring back has to be the most recent. I do have a date_created column on my table as well as a date_last_updated column. So basically using the select statement below as an example this query could return lets say 5 rows, I however only want it to return the most recent row and the most recent row is determined by the date_last_updated (which will only be populated if the record has been updated otherwise it is null) or the date_created fields.
    select * from my_table
    where model_id = 234
    Any help on this matter would be greatly appreciated.
    Thank you.

    Hi,
    you can do; -
    select *
    from
    (select *
    from my_table
    order by creation_date desc)
    where rownum = 1This does not guarantee that you will get the most recent in cases of records being created at exactly the same time, but if your table has a prime key then you could use this as the order by to get the same effect, though if say 5 records are inserted as a batch what does it really mean to be inserted last....
    regards,
    Robert.
    Edited by: Robert Angel on 09-Jul-2012 08:22 to add code tags.

  • SQL to compare 2 most recent rows in table

    Hi,
    I am trying to compare STATUS fields ( Most recent to Next Most recent )
    and select Most recent row if there STATUS values are different.
    SQL :
    select c.id,c.effdt,c.end_dt,c.status
    from table c ,table k
    where c.id = k.id
    and c.status <> k.status
    SAMPLE DATA
    ID EFFDT END_DT STATUS
    6 10/10/2006 12/31/9999 Y
    6 10/01/2006 10/09/2006 N
    6 09/02/2006 09/30/2006 Y
    EXPETING O/P
    6,10/10/2006 , 12/31/9999 , Y
    but with the above SQL i am getting 3 rows with same data .
    6,10/10/2006 , 12/31/9999 , Y
    6,10/10/2006 , 12/31/9999 , Y
    6,10/10/2006 , 12/31/9999 , Y
    is there a way to select only one row without using DISTINCT ?
    i can't use DISTINCT keyword because if sample data contains
    below data my SQL compares 1st row and 4th row since STATUS are not
    equal and returns results which we dont want . we just want
    to compare Most recent and next most recent ( i.e first and second rows
    only )
    SAMPLE DATA
    ID EFFDT END_DT STATUS
    6 10/10/2006 12/31/9999 Y
    6 10/01/2006 10/09/2006 Y
    6 09/02/2006 09/30/2006 Y
    6 08/01/2006 09/01/2006 N
    Best regards,
    Karru

    Try this
    SELECT *
    FROM
         (SELECT end_dt,
              status,
              lead(status) over(PARTITION BY id
            ORDER BY end_dt DESC) AS
           next_status
            FROM qry
            ORDER BY end_dt DESC)
    WHERE NVL(status,'Z') <> next_status
    AND rownum = 1

  • How to get most recent consecutive records with the same value

    Hi,
    Can someone please help me to solve my problem?
    Below is my table
    Prod_Code-----Purchase_date---Inv_number-------Inv_amt
    MS_AV16850------18/01/2005-----------6575947----------------7.93
    MS_AV16850------22/07/2005-----------7034012----------------51.82
    MS_AV16850------04/01/2006-----------8719618----------------51.82
    MS_AV16850------20/06/2006-----------9515864----------------104.69
    MS_AV16850------16/04/2007-----------10353759----------------189.29
    MS_AV16850------30/05/2007-----------10689899----------------189.29
    MS_AV16850------06/01/2008-----------1653821----------------65.49
    MS_AV16850------22/02/2009-----------10866311----------------189.29
    I want my query to show the rows that has most recent purchase dates with same amount in consecutive purchase date.
    So from the table above, the query should display:
    Prod_Code-----Purchase_date---Inv_number-------Inv_amt
    MS_AV16850------16/04/2007-----------10353759----------------189.29
    MS_AV16850------30/05/2007-----------10689899----------------189.29
    It should not get
    MS_AV16850------16/04/2007-----------10353759----------------189.29
    MS_AV16850------30/05/2007-----------10689899----------------189.29
    MS_AV16850------22/02/2009-----------10866311----------------189.29
    because inv_number 10866311 has a prvevious inv_amount of 65.49.
    and not get this
    MS_AV16850------22/07/2005-----------7034012----------------51.82
    MS_AV16850------04/01/2006-----------8719618----------------51.82
    because they are not the most recent purchase date even if they have the same inv_amount.
    Thanks in advance.

    Hi,
    You're right; thanks for catching my mistake.
    I changed the WHERE clause of the main query (including subquery there) to deal with that situation:
    WITH     got_grp          AS
         SELECT      x.*
         ,      ROW_NUMBER () OVER ( ORDER BY      purchase_date )
                - ROW_NUMBER () OVER ( PARTITION BY  inv_amt
                                             ORDER BY         purchase_date )     AS grp
    --     ,      ROW_NUMBER () OVER ( ORDER BY      purchase_date )     AS r1
    --     ,        ROW_NUMBER () OVER ( PARTITION BY  inv_amt
    --                                         ORDER BY         purchase_date )     AS r2
         FROM     table_x     x
    SELECT     *     -- Or list all columns except grp
    FROM     got_grp
    WHERE     (inv_amt, grp)  IN  (
                               SELECT    MAX (inv_amt) KEEP (DENSE_RANK LAST ORDER BY MAX (purchase_date))
                        ,       MAX (MAX (grp))
                                FROM      got_grp
                                GROUP BY  grp
                                ,       inv_amt
                                HAVING    COUNT (*)     > 1
    ;Thanks, too, for posting the sample data. Apparantly, you're more interested in solving this problem than OP is.
    Edited by: Frank Kulash on Nov 22, 2010 1:36 PM
    The r1 and r2 columns are not needed for the solution. You may want to display them, just to help see how the query works.

  • How to determine most recent date from the date column of internal table

    Dear friends
    would you like to tell me. how i determine the most recently changed record by looking at date and time from internal table i am not supposed to sort the table by date and time... I must check date and time with other records date and time to determine which record is most recently changed...
    here the scenario is.
    id idnumber chdate chtime
    1 123456 20060606 135312
    2 123456 20060606 135900
    3 123456 20060606 132300
    4 123457 20060606 140000
    5 123457 20060606 142500
    in the above scenario i must keep in my mind that the most recently changed record is identical to its idnumber i can say that:
    the record should be fetched this way
    id idnumber chdate chtime
    3 123456 20060606 132300
    5 123457 20060606 142500
    because here the id 3 is the most recently changed in the idnumber 123456
    where id 5 is the most recently changed in the idnumber 123457
    please help me to determin how i am supposed to carry out this task any suggestion, code will be great help of mine.
    regards
    Naim

    After testing my suggestion above, I realized that it doesn't work because the delete adjacent actually will keep the first one and delete the rest.  I'm working with Srinivas's code a bit now,  I think it is almost what you want.  I am under the impression that you dont' want to HIGHest date/time, but just the last record of the sequence, if this is the case, then this code will help.  Here we will assign an index to each record per the idnumber, that way we can sort it and get the lastest record.
    report zrich_0001.
    types: begin of itab_type,
            id       type i,
            idnumber type i,
            chdate   like sy-datum,
            chtime   like sy-uzeit.
    types: end of itab_type.
    types: begin of itab_type2,
            id       type i,
            idnumber type i,
            index    type i,
            chdate   like sy-datum,
            chtime   like sy-uzeit.
    types: end of itab_type2.
    data: itab     type table of itab_type with header line,
          itab2    type table of itab_type2 with header line,
          prev_rec type itab_type.
    data: v_id type i.
    start-of-selection.
      itab-id       = 1.
      itab-idnumber = 123456.
      itab-chdate   = '20060606'.
      itab-chtime   = '135312'.
      append itab. clear itab.
      itab-id       = 2.
      itab-idnumber = 123456.
      itab-chdate   = '20060606'.
      itab-chtime   = '135900'.
      append itab. clear itab.
      itab-id       = 3.
      itab-idnumber = 123456.
      itab-chdate   = '20060606'.
      itab-chtime   = '142500'.
      append itab. clear itab.
      itab-id       = 4.
      itab-idnumber = 123457.
      itab-chdate   = '20060606'.
      itab-chtime   = '140000'.
      append itab. clear itab.
      itab-id       = 5.
      itab-idnumber = 123457.
      itab-chdate   = '20060606'.
      itab-chtime   = '120000'.
      append itab.
      clear itab.
    <b>  data: counter type i.
    * Assign an index to each row per idnumber
      loop at itab.
        on change of itab-idnumber.
        if sy-tabix > 1.
          clear counter.
          endif.
        endon.
        clear itab2.
        move-corresponding itab to itab2.
        counter = counter + 1.
        itab2-index = counter.
        append itab2.
      endloop.
    * Sort it and get rid of older records.
      sort itab2  by idnumber ascending
                     index descending.
      delete adjacent duplicates from itab2 comparing idnumber.</b>
      read table itab2 with key idnumber = '123456'.
      write:/ itab2-chdate, itab2-chtime.
      read table itab2 with key idnumber = '123457'.
      write:/ itab2-chdate, itab2-chtime.
    Regards,
    Rich Heilman

  • Query most recent date

    I do not know how to accomplish querying a table on an index for a single value representing the record with the most recent datetime.
    The table looks like:
    CREATE TABLE PartReceipt(
    Id [int] IDENTITY(1,1) NOT NULL,
    PartId [int] NOT NULL,
    UnitCost decimal(8,2) NOT NULL,
    DateInserted [datetime] NOT NULL)
    PartId is a foreign key into the Part table.
    I tried:
    select unitcost from partreceipt  where partid=583  having max(dateinserted)
    but received this error:
    An expression of non-boolean type specified in a context where a condition is expected, near ')'.

    >> The table looks like: <<
    I hope not! 
    A table models a set, so its name has to be plural or a collective name. Do you really have only one receipt? 
    A table has to have a key by definition. 
    We do not use IDENTITY in RDBMS. Why would the proprietary table property that counts physical insertion attempts be part of a valid data model? 
    Identifiers are never numeric. What math do you do with it? None. How do you get validation and verification with a numeric? 
    Why did you use an old Sybase DATETIME and not a DATE or even a DATETIME2(0)?
    Why did you fail to post the DRI in your narrative? 
    Insertion is a physical event and has nothing to do with a logical data model.  Your “DateInserted” violates both ISO-11179 rules and logic. 
    Here is one guess, but in another design we could have (receipt_date, part_id) as a key. This would mean that you get a daily shipment.
    CREATE TABLE Part_Receipts
    (receipt_nbr CHAR(10) NOT NULL PRIMARY KEY,
     receipt_date DATE DEFAULT CURRENT_TIMESTAMP NOT NULL,
     part_id CHAR(10) NOT NULL
       REFERENCES Parts(part_id),
     unit_cost DECIMAL(8,2) NOT NULL
      CHECK (unit_cost >= 0.00),
    SELECT unit_cost, MAX(receipt_date)AS max_receipt_date
      FROM Part_Receipts
     WHERE part_id = '0000000583';
    Your HAVING clause made no sense; there was no predicate in it. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How to select Most recent record with rest of record in ascending order...?

    Dear Expert,
    I have one table called Tab1 & have a lot columns. For this schenario, i mentioned few of the columns.
    The columns are
    product_type varchar2(100),
    curr_date date (storing with time stamp),
    other1_cloumn varchar2(10),
    other2_cloumn varchar2(10)
    Now I want to display all the records in ascending order except most recent record for every product_type || Union all || Most recent records in ascending order in single query.
    For example...
    product_type curr_date date other1_cloumn other2_cloumn
    1, "10-May-2005 10:10:10", 10, 10
    1, "10-May-2005 10:10:11", 10, 10
    1, "10-May-2005 10:10:12", 10, 10
    1, "10-May-2005 10:10:09", 10, 10
    2, "10-May-2005 10:10:10", 10, 10
    2, "10-May-2005 10:10:11", 10, 10
    2, "10-May-2005 10:10:12", 10, 10
    2, "10-May-2005 10:10:09", 10, 10
    3, "10-May-2005 10:10:10", 10, 10
    3, "10-May-2005 10:10:11", 10, 10
    3, "10-May-2005 10:10:12", 10, 10
    3, "10-May-2005 10:10:09", 10, 10
    Now I want to display (OUTPUT) like...
    1, "10-May-2005 10:10:10", 10, 10
    1, "10-May-2005 10:10:11", 10, 10
    1, "10-May-2005 10:10:09", 10, 10
    2, "10-May-2005 10:10:10", 10, 10
    2, "10-May-2005 10:10:11", 10, 10
    2, "10-May-2005 10:10:09", 10, 10
    3, "10-May-2005 10:10:10", 10, 10
    3, "10-May-2005 10:10:11", 10, 10
    3, "10-May-2005 10:10:09", 10, 10
    1, "10-May-2005 10:10:12", 10, 10
    2, "10-May-2005 10:10:12", 10, 10
    3, "10-May-2005 10:10:12", 10, 10
    Plz, provide a solution....

    I want to display like...
    select * from tab1 where (product_type,curr_date) in
    (select product_type,max(curr_date) from tab1 group by product_type)
    order by product_type
    Union All
    (select * from tab1 where (product_type,curr_date) NOT IN
    (select product_type,max(curr_date) from tab1 group by product_type)
    order by product_type)
    But, In the above case, The ORDER BY Clause will not work...How to get this one...?
    I mean.. I want to display all the records in ascending order except Most recent record base on Product type and next I want to display Most recent record in ascending order. I want to display both cases in a single query...?

  • How to see most recent posts per forum

    Hi, all;
    It seems to me that I'm not "getting" something about the organization of the forums. What I want to do is see the posts in each forum that I am interested in, most recent first. What I actually see when I go to each forum is "trending" discussions. When I go to Browse>Discussions, I can see that some of the most recent discussions aren't getting into the "Trending" category, but Browse>Discussions shows a jumbled mess of all forums.
    I'd like to help these people, but I fear their questions are falling through the cracks, since they're not "trendy" enough for me to be able to see them.  How can I see "recent" discussions instead of "trending" ones.
    Regards;
    Amy

    Hi Amy, you might not have gotten a lot of responses posting in the forum dedicated to community help. Next time, for forum-related questions, rather use this page: http://forums.adobe.com/community/general/forum_comments?view=discussions

  • How to make most recent messages appear at the top of the list?

    I can not find a place in Mail preferences to make my messages in each mailbox ALWAYS appear with the most recent at the top of the list. They seem to revert to the reverse order, even though I laboriously change the order in each mailbox via clicking the top of the date column. I am using primarily .Mac addresses in IMAP format, and three computers. It seems that after I shut down, then restart the next day and my computers all sycn with .Mac, the order goes back to oldest first. How can I fix this? Thanks!

    Everytime i have used webmail, the view is always retained with my previous settings. In fact the .Mac web mail help menu says the same thing (see below)
    Therefore the last thing i would recommend is to simply reset safari (which will empty the cache), delete all your Mail plist files, and not turn .Mac sync on fully until all systems are sorting consistently on their own....
    (from the .mac help menu)
    ===================
    Sorting message lists
    When you use .Mac Mail on the web, you can sort your messages, drafts, and sent messages lists by their column headers. Sorting is helpful when you want to quickly locate specific emails or groups of emails, such as all messages received from a specific sender or all flagged messages.
    To sort a message list:
    If you're not already in .Mac Mail on the web, go to www.mac.com and click Mail (at the top of the page), and log in.
    Access a message list by opening a folder.
    Click any column header to sort the list by that parameter. Clicking the same column header again reverses the order in which the list is sorted.
    When you sort a message list, all email messages in the list are sorted, not just those showing on the current page.
    Column headers vary slightly by list. The Drafts list, for example, has no From column.
    After you have sorted a list, it retains that order until you re-sort it.

  • Collapsed view: how to see "most recent unread message" instead of "first unread message" in a thread in Mail

    Hey all,
    I use the inbuilt Mail-software on my Macbook with Lion 10.7 and I constantly overlook new messages in a thread, as I organize by conversation and usually have all my threads in 'collapsed view'. For some reason Mail seems to prefer showing the 'first', i.e. the earliest unread message as the one message that I see in collapsed. If there are newer messages already in the thread, I don't see them, unless I un-collapse the thread. I find this really unintuitive and annoying, my inbox seems far more static than it really is.
    Is there any way to change this and have Mail show me the most recent unread message as the message I see in collapsed view?
    I appreciate any advice.
    Thanks, Carl
    PS: BTW, I have the same problem on my iPhone, double props to you if you can solve it for both Mail and iPhone!

    Mail
    Preferences
    Viewing
    Check put most recent message at top

  • How to get a specific Row based on filter on a specific column value

    Friends,
    I have a requirement to fetch a row, maximum salary of an employee row from employee table using ADF View object, I have a view object with result set based on some critieria, now I have to get a row out of result set which is having maximum employee salary.
    Please put your thoughts or experiences!!
    Thanks

    You should be able to add a transient attribute called maxSalary and use groovy functions to find vo.max(Salary) like -
    https://blogs.oracle.com/adf/entry/using_groovy_aggregate_functions_in
    How to calculate ADF table column [check Laura Akel's post]Then you can create a view criteria which equates the salaryfield to maxSalary and returns just one row.

  • How to query the master block based on one of the values in detail block

    Hi,
    In version 6i forms, I have a field in data block which is not set as a database item. I am using that field to store a value from detail block. If I want to query the form using that field (which represents one of the values from detail block), how do I do that? Any pointers?
    TIA,

    Do you want to query a master, which contains a specific detail? If so, here's an example how you could do it with a PRE-QUERY-trigger:
    DECLARE
      vcQuery VARCHAR2(4000);
    BEGIN
      IF :MASTERBLOCK.THE_DETAIL_SEARCH_ITEM IS NOT NULL THEN
        -- Build up an exists Sub-Query
        vcQuery:=' MASTERBLOCKID IN (SELECT FK_TO_MASTERBLOCK FROM DETAILTABLE WHERE DETAIL_COLUMN=''' || :MASTERBLOCK.THE_DETAIL_SEARCH_ITEM|| ''')';
      END IF;
      SET_BLOCK_PROPERTY('MASTERBLOCK', DEFAULT_WHERE, vcQuery);
    END;

  • How to query the selected row?

    i have a table displayed in a gridcontrol... how would i go about binding a controlButton to this table so that when this button is clicked, it returns the value of a particular column that is currently selected in the gridcontrol??? ... currently, when the button is clicked... it returns the top of the ResultSet which is always the same value... i would like it to return the value of the row that is currenlty selected in the table??? ... using infoProducers(sessionInfo and resultSetInfo)... thanx, james

    After using bellow script it works fine
    xfa.resolveNode("Formname.Table1.Row1["this.parent.index"].fieldname").rawValue;

  • How to get most recently view pages in new tab on the new version of firefox

    upgraded to the new firefox and now i cannot get my recently viewed site to show when i open a new tab. the little square that is supposed to turn them on and off is not showing up.

    You can check if the new tab is still set to the about:newtab page.
    You can check the browser.newtab.url pref on the <b>about:config</b> page.
    * browser.newtab.url = about:newtab
    You can open the <b>about:config</b> page via the location/address bar.
    You can accept the warning and click "I'll be careful" to continue.
    *http://kb.mozillazine.org/about:config
    See also this article about the New Tab page (about:newtab):
    *https://support.mozilla.org/kb/new-tab-page-show-hide-and-customize-top-sites

  • How can I update multiple rows based on comparison of fields table1 and 2

    I create the following SQL to test what I thought was a method to update those records where the fields below match, but what ends up happening is that the update functions works the first time, and then basically updates everything to null. I am not understanding what I am doing wrong. New at this.
    UPDATE SLS_HDR B
    SET ( B.ORD_DT, B.SHIP_ADD_CD, B.INV_ADD_CD, B.LOB, B.STATUS,
    B.ORD_TYPE, B.HDR_ROUTE, B.PRICE_LIST, B.CUST_ORDER, B.REF_A, B.REF_B,
    B.ORD_REF, B.ORD_DISC, B.SREP, B.SREP2, B.PLAN_DEL_DT, B.TXTA, B.TXTB,
    B.INV_CONTACT, B.SHIP_CONTACT, B.SOLD_CONTACT, B.PAY_CONTACT, B.ORD_AMT,B.UPDATED_DT )
    = (SELECT
    A.ORD_DT, A.SHIP_ADD_CD, A.INV_ADD_CD, A.LOB, A.STATUS,
    A.ORD_TYPE, A.HDR_ROUTE, A.PRICE_LIST, A.CUST_ORDER, A.REF_A, A.REF_B,
    A.ORD_REF, A.ORD_DISC, A.SREP, A.SREP2,A.PLAN_DEL_DT, A.TXTA, A.TXTB,
    A.INV_CONTACT, A.SHIP_CONTACT, A.SOLD_CONTACT,A.PAY_CONTACT, A.ORD_AMT, SYSDATE
    FROM
    SLS_HDR_TEMP A
    WHERE
    A.FIN_COMP = B.FIN_COMP AND
    A.LOG_COMP = B.LOG_COMP AND
    A.ORD_NO = B.ORD_NO AND
    A.TRANS_DT = B.TRANS_DT AND
    A.BP_TYPE = B.BP_TYPE AND
    A.STATUS <> B.STATUS);
    Can anyone advise?
    Thank you,
    Edited by: 903292 on Dec 19, 2011 1:15 PM

    you donot have where clause in your update so un-matched rows will be updated with null values
    UPDATE SLS_HDR B
    SET ( B.ORD_DT, B.SHIP_ADD_CD, B.INV_ADD_CD, B.LOB, B.STATUS,
    B.ORD_TYPE, B.HDR_ROUTE, B.PRICE_LIST, B.CUST_ORDER, B.REF_A, B.REF_B,
    B.ORD_REF, B.ORD_DISC, B.SREP, B.SREP2, B.PLAN_DEL_DT, B.TXTA, B.TXTB,
    B.INV_CONTACT, B.SHIP_CONTACT, B.SOLD_CONTACT, B.PAY_CONTACT, B.ORD_AMT,B.UPDATED_DT )
    = (
              SELECT
              A.ORD_DT, A.SHIP_ADD_CD, A.INV_ADD_CD, A.LOB, A.STATUS,
              A.ORD_TYPE, A.HDR_ROUTE, A.PRICE_LIST, A.CUST_ORDER, A.REF_A, A.REF_B,
              A.ORD_REF, A.ORD_DISC, A.SREP, A.SREP2,A.PLAN_DEL_DT, A.TXTA, A.TXTB,
              A.INV_CONTACT, A.SHIP_CONTACT, A.SOLD_CONTACT,A.PAY_CONTACT, A.ORD_AMT, SYSDATE
              FROM
              SLS_HDR_TEMP A
              WHERE
              A.FIN_COMP = B.FIN_COMP AND
              A.LOG_COMP = B.LOG_COMP AND
              A.ORD_NO = B.ORD_NO AND
              A.TRANS_DT = B.TRANS_DT AND
              A.BP_TYPE = B.BP_TYPE AND
              A.STATUS= B.STATUS
    WHERE EXISTS
         select null from SLS_HDR_TEMP A
         WHERE
         A.FIN_COMP = B.FIN_COMP AND
         A.LOG_COMP = B.LOG_COMP AND
         A.ORD_NO = B.ORD_NO AND
         A.TRANS_DT = B.TRANS_DT AND
         A.BP_TYPE = B.BP_TYPE AND
         A.STATUS= B.STATUS
    )OR using Merge
    Merge into SLS_HDR B
    using SLS_HDR_TEMP A
    on (A.FIN_COMP = B.FIN_COMP AND
    A.LOG_COMP = B.LOG_COMP AND
    A.ORD_NO = B.ORD_NO AND
    A.TRANS_DT = B.TRANS_DT AND
    A.BP_TYPE = B.BP_TYPE AND
    A.STATUS= B.STATUS)
    when matched then update set (B.ORD_DT, B.SHIP_ADD_CD, B.INV_ADD_CD, B.LOB, B.STATUS,
    B.ORD_TYPE, B.HDR_ROUTE, B.PRICE_LIST, B.CUST_ORDER, B.REF_A, B.REF_B,
    B.ORD_REF, B.ORD_DISC, B.SREP, B.SREP2, B.PLAN_DEL_DT, B.TXTA, B.TXTB,
    B.INV_CONTACT, B.SHIP_CONTACT, B.SOLD_CONTACT, B.PAY_CONTACT, B.ORD_AMT,B.UPDATED_DT ) = (A.ORD_DT, A.SHIP_ADD_CD, A.INV_ADD_CD, A.LOB, A.STATUS,
    A.ORD_TYPE, A.HDR_ROUTE, A.PRICE_LIST, A.CUST_ORDER, A.REF_A, A.REF_B,
    A.ORD_REF, A.ORD_DISC, A.SREP, A.SREP2,A.PLAN_DEL_DT, A.TXTA, A.TXTB,
    A.INV_CONTACT, A.SHIP_CONTACT, A.SOLD_CONTACT,A.PAY_CONTACT, A.ORD_AMT, SYSDATE)HTH...
    Thanks

Maybe you are looking for