Delimiter //
/**
 * Author:  armen
 * Created: 29 janv. 2018
 */
Drop Procedure if exists LOADER_MEMBERSACCRED_NORMALIZE_MAP_FUNCTION_PROVIDED//

Create Procedure LOADER_MEMBERSACCRED_NORMALIZE_MAP_FUNCTION_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_FUNCTIONS fct
            On src.DF_FUNCTIONS_SHORT_LABEL = fct.DF_FUNCTIONS_SHORT_LABEL
            And fct.ADMIN_PARAMS_ID_ADMIN_PARAMS = @id_admin_params
    Set
        src.DF_FUNCTIONS_ID_DF_FUNCTIONS = fct.ID_DF_FUNCTIONS
        , sts.LOADER_STATUS_WARNCOUNT = (
                CASE WHEN fct.ID_DF_FUNCTIONS IS NULL THEN 
                    sts.LOADER_STATUS_WARNCOUNT + 1
                ELSE 
                    sts.LOADER_STATUS_WARNCOUNT
                END
            )
        , sts.LOADER_STATUS_WARNMSGS = (
                CASE WHEN fct.ID_DF_FUNCTIONS IS NULL THEN 
                    LOADER_CONCAT_ERR(sts.LOADER_STATUS_WARNMSGS, Concat('Fonction abrégée à créer : ', src.DF_FUNCTIONS_SHORT_LABEL) )
                ELSE sts.LOADER_STATUS_WARNMSGS
                END
            )
    Where 
        sts.LOADER_STATUS_BATCH_NUM = batchnum 
        And Trim(Coalesce(src.DF_FUNCTIONS_SHORT_LABEL, '')) <> ''
    ;
End //
Delimiter ;