Delimiter //
/**
    In batchnum Int : num du lot
*/
Drop Procedure if exists LOADER_ACCOUNTS_COPY_CONTACTS_ACCOUNTS_UPDATE//
Create Procedure LOADER_ACCOUNTS_COPY_CONTACTS_ACCOUNTS_UPDATE (
    In batchnum int, 
    In lastId Int
)
Begin
    Update
        LOADER_STATUS LDST
        Inner Join LOADER_CONTACTS_ACCOUNTS LDCTACC
            On LDST.ID_LOADER_STATUS = LDCTACC.LOADER_STATUS_ID_LOADER_STATUS
    Set
        LDCTACC.ACCOUNTS_ID_ACCOUNTS = LDCTACC.ACCOUNTS_ID_ACCOUNTS_NEW + lastId
    Where
        LDST.LOADER_STATUS_BATCH_NUM = batchnum
        And LDST.LOADER_STATUS_ERRCOUNT = 0
        And LDCTACC.ACCOUNTS_ID_ACCOUNTS_NEW Is Not Null
        And LDCTACC.ACCOUNTS_ID_ACCOUNTS_NEW <> 0
    ;
    Update
        LOADER_STATUS LDST
        Inner Join LOADER_ACCOUNTS_REPLICATION LAR
            On LDST.ID_LOADER_STATUS = LAR.LOADER_STATUS_ID_LOADER_STATUS
    Set
        LAR.ID_ACCOUNTS = LAR.ID_ACCOUNTS_NEW + lastId
    Where
        LDST.LOADER_STATUS_BATCH_NUM = batchnum
        And LDST.LOADER_STATUS_ERRCOUNT = 0
        And LAR.ID_ACCOUNTS_NEW Is Not Null
        And LAR.ID_ACCOUNTS_NEW <> 0
    ;
End //

Delimiter ;

