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

    Update
        LOADER_STATUS STS
        Inner Join LOADER_RECLAIMS LRD
            On LRD.LOADER_STATUS_ID_LOADER_STATUS = STS.ID_LOADER_STATUS
		Inner Join DF_RECLAIMS_OPINION DFRO
			On LRD.DF_RECLAIMS_OPINION_CODE = DFRO.DF_RECLAIMS_OPINION_CODE
    Set
        LRD.RECLAIMS_DETAILS_OPINION = DFRO.ID_DF_RECLAIMS_OPINION
    Where
        STS.LOADER_STATUS_BATCH_NUM = batchnum
		And STS.LOADER_STATUS_ERRCOUNT = 0
    ;


    -- maj des erreur

	call LOADER_BUILD_RECLAIMS_CHECK_BASE_QUERY (
				'DF_RECLAIMS_OPINION_CODE', batchnum, 'Opinion code not defined', '', 0, @query
			)
		;
	set @query = Concat(@query
					, ' And Coalesce(DF_RECLAIMS_OPINION_CODE, '''') <> '''' '
					, ' And RECLAIMS_DETAILS_OPINION Is Null'
				)
			;

	PREPARE stmt FROM @query;
	execute stmt			
		;
	Deallocate prepare stmt;

End//
Delimiter ;