Delimiter //
/**
 * If language is not provided, use the Admin Param language by default
 * 
 * @param int batchnum
 * @author Benoit
 * @ticket #2125
 */ 
Drop Procedure if Exists LOADER_CONTACTS_NORMALIZE_MAP_LANGUAGE_NOT_PROVIDED//
 
Create Procedure LOADER_CONTACTS_NORMALIZE_MAP_LANGUAGE_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 ADMIN_PARAMS A
            ON A.ID_ADMIN_PARAMS = @idAdminParams
    SET
        C.DF_LANGUAGES_ID_DF_LANGUAGES = A.DF_LANGUAGES_ID_DEF_LANGUAGE
    WHERE
        S.LOADER_STATUS_BATCH_NUM = batchnum
        AND C.ID_CONTACTS_NEW IS NOT NULL
        AND Coalesce(C.DF_LANGUAGES_CODE, '') = ''
   ;
    
End //
Delimiter ;
