Delimiter //
/**
**/
Drop Procedure if exists LOADER_MEMBERSACCRED_NORMALIZE_MAP_PROFILES_PROVIDED//

Create Procedure LOADER_MEMBERSACCRED_NORMALIZE_MAP_PROFILES_PROVIDED (
    In batchnum int
)
Begin
    Set @id_admin_params = GET_LOADER_INFO('ID_ADMIN_PARAMS', batchnum);

    Update
        LOADER_STATUS sts
        Inner Join LOADER_MEMBERSACCRED src
            On sts.ID_LOADER_STATUS = src.LOADER_STATUS_ID_LOADER_STATUS
        Left Join (
            DF_ACCESS_PROFILES dfap
            Inner Join ADMIN_PARAMS admp
                On dfap.UNIVERS_ID_UNIVERS = admp.UNIVERS_ID_UNIVERS
                And admp.ID_ADMIN_PARAMS = @id_admin_params
        )
            On src.DF_ACCESS_PROFILES_CODE = dfap.DF_ACCESS_PROFILES_CODE
    Set
        src.DF_ACCESS_PROFILES_ID_DF_ACCESS_PROFILES = dfap.ID_DF_ACCESS_PROFILES
        , sts.LOADER_STATUS_WARNCOUNT = (
                CASE WHEN dfap.ID_DF_ACCESS_PROFILES IS NULL THEN 
                    sts.LOADER_STATUS_WARNCOUNT + 1
                ELSE 
                    sts.LOADER_STATUS_WARNCOUNT
                END
            )
        , sts.LOADER_STATUS_WARNMSGS = (
                CASE WHEN dfap.ID_DF_ACCESS_PROFILES IS NULL THEN 
                    LOADER_CONCAT_ERR(sts.LOADER_STATUS_WARNMSGS, Concat('Profile non trouvé : ', src.DF_ACCESS_PROFILES_CODE) )
                ELSE sts.LOADER_STATUS_WARNMSGS
                END
            )
    Where 
        sts.LOADER_STATUS_BATCH_NUM = batchnum 
        And Trim(Coalesce(src.DF_ACCESS_PROFILES_CODE, '')) <> ''
    ;

End //
Delimiter ;