Delimiter //
/**
 * 
 */ 
Drop Procedure If Exists LOADER_ACCOUNTS_NORMALIZE_MAP_RATE_CODE_PROVIDED//
Create Procedure LOADER_ACCOUNTS_NORMALIZE_MAP_RATE_CODE_PROVIDED(
    In batchnum Int
)
Begin

    Set @idAdminParams = GET_LOADER_INFO('ID_ADMIN_PARAMS', batchnum);

    Update
        LOADER_STATUS LS
        Inner Join LOADER_ACCOUNTS LA
            On LA.LOADER_STATUS_ID_LOADER_STATUS = LS.ID_LOADER_STATUS
        Left Join DF_RATE_GRID RA
            On RA.DF_RATE_GRID_CODE = LA.DF_RATE_GRID_CODE
            And RA.ADMIN_PARAMS_ID_ADMIN_PARAMS = @idAdminParams
    Set
        LA.DF_RATE_GRID_ID_DF_RATE_GRID = RA.ID_DF_RATE_GRID
        , LS.LOADER_STATUS_WARNCOUNT = 
            (Case When RA.ID_DF_RATE_GRID Is Null
                Then LS.LOADER_STATUS_WARNCOUNT + 1
                Else LS.LOADER_STATUS_WARNCOUNT
            End)
        , LS.LOADER_STATUS_WARNMSGS = 
            (Case When RA.ID_DF_RATE_GRID Is Null
                Then LOADER_CONCAT_ERR(LS.LOADER_STATUS_WARNMSGS, Concat('Code intérêts inexistant : "', LA.DF_RATE_GRID_CODE, '"'))
                Else LS.LOADER_STATUS_WARNMSGS
            End)
    Where
        LS.LOADER_STATUS_BATCH_NUM = batchnum 
        And Coalesce(LA.DF_RATE_GRID_CODE, '') != '';
End//
Delimiter ;