Update or merge field from 2nd table - DB2 iSeries

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • martyy
    New Member
    • Mar 2013
    • 2

    #1

    Update or merge field from 2nd table - DB2 iSeries

    I am working on an iSeries v7r1 to consolidate customer accounts after de-deuplication. I am struggling with a fairly simply update to a single field from a value in another table.

    tbl_target
    CUSTNUM

    tbl_source
    CUSTNUM_NEW
    CUSTNUM_OLD
    MASTER

    What I need to do is
    UPDATE tbl_target.CUST NUM=tbl_source. CUSTNUM_NEW WHERE tbl_target.CUST NUM = tbl_source_OLD ONLY getting the records from tbl_source.MAST ER=0


    I can post the SQL I have tried tomorrow but thought it might be easier explained without.
  • martyy
    New Member
    • Mar 2013
    • 2

    #2
    I was able to do the merge using the following code.

    Code:
    MERGE INTO tbltarget AS A
     
    USING (
     
    SELECT B.CUSTNUM_NEW, B.CUSTNUM_OLD, B.MASTER FROM tblsource B 
    ) AS B ON (
     
    B.CUSTNUM_OLD = A.CUSTNUM AND B.MASTER='0'
     
    )
     
    WHEN MATCHED THEN
     
    UPDATE SET 
    A.CUSTNUM = B.CUSTNUM;

    Comment

    Working...