Delimiter //
/**
 * Find the id of the given account
 * 
 * @author Jean-François
 */
Drop Procedure If Exists LOADER_BALANCECONTROL_NORMALIZE_MAP_ACCOUNT//
Create Procedure LOADER_BALANCECONTROL_NORMALIZE_MAP_ACCOUNT(
    In batchnum Int
)
Begin
    

    Set @idEntities = GET_LOADER_INFO('ID_ENTITIES', batchnum);

    Update
        LOADER_STATUS S
        Inner Join
            LOADER_BALANCECONTROL BC
            on BC.LOADER_STATUS_ID_LOADER_STATUS = S.ID_LOADER_STATUS
        Inner Join ACCOUNTS A
            On A.ACCOUNTS_REF = BC.ACCOUNTS_REF
            And A.ENTITIES_ID_ENTITIES = @idEntities
    Set
        BC.ID_ACCOUNTS = A.ID_ACCOUNTS
    Where
        S.LOADER_STATUS_BATCH_NUM = batchnum
    ;

End//
Delimiter ;