Delimiter //
/**
 * Check if the given account exists
 * 
 * @author Jean-François
 */
Drop Procedure If Exists LOADER_BALANCECONTROL_NORMALIZE_CHECK_ACCOUNT_EXISTS//
Create Procedure LOADER_BALANCECONTROL_NORMALIZE_CHECK_ACCOUNT_EXISTS(
    In batchnum Int
)
Begin

    Update
        LOADER_STATUS S
        Inner Join
            LOADER_BALANCECONTROL BC
            on BC.LOADER_STATUS_ID_LOADER_STATUS = S.ID_LOADER_STATUS
    Set
        S.LOADER_STATUS_ERRCOUNT = S.LOADER_STATUS_ERRCOUNT + 1
        , S.LOADER_STATUS_ERRMSGS = LOADER_CONCAT_ERR(S.LOADER_STATUS_ERRMSGS, CONCAT('Compte ref ', BC.ACCOUNTS_REF, ' non trouvé dans l''application. Solde attendu : ', Coalesce(BC.BALANCE,0) ) ) 
    Where
        S.LOADER_STATUS_BATCH_NUM = batchnum
        And BC.ID_ACCOUNTS Is Null
    ;


End//
Delimiter ;