Delimiter //
/**
 * If the function is not provided, use the admin param prefered function
 * 
 * @param int batchnum
 * @author Benoit
 * @ticket #2110
 */ 
Drop Procedure if Exists LOADER_CONTACTS_NORMALIZE_MAP_FUNCTION_NOT_PROVIDED//
 
Create Procedure LOADER_CONTACTS_NORMALIZE_MAP_FUNCTION_NOT_PROVIDED (
    In batchnum int
)
Begin
 
    Set @idAdminParams = GET_LOADER_INFO('ID_ADMIN_PARAMS', batchnum);
 
    UPDATE
        LOADER_CONTACTS C
        INNER JOIN LOADER_STATUS S
            ON S.ID_LOADER_STATUS = C.LOADER_STATUS_ID_LOADER_STATUS
        INNER JOIN DF_FUNCTIONS F
            ON F.ADMIN_PARAMS_ID_ADMIN_PARAMS = @idAdminParams
            AND F.DF_FUNCTIONS_PREFERENCE = 1
    SET
        C.DF_FUNCTIONS_ID_DF_FUNCTIONS = F.ID_DF_FUNCTIONS
    WHERE
        S.LOADER_STATUS_BATCH_NUM = batchnum
        AND C.ID_CONTACTS_NEW IS NOT NULL
        AND Coalesce(C.DF_FUNCTIONS_SHORT_LABEL, '') = ''
   ;
    
End //
Delimiter ;
