Delimiter //
/**
    In batchnum Int : num du lot
*/

Drop Procedure if exists LOADER_REFDATALABEL_REF_DATA_UPDATE//

Create Procedure LOADER_REFDATALABEL_REF_DATA_UPDATE (
    In batchnum int
)
Begin

	Update 
		ENTITIES_REF_DATAS_LNG TAR
		Inner Join LOADER_REFDATALABEL SRC
			On TAR.ID_ENTITIES_REF_DATAS_LNG = SRC.ID_ENTITIES_REF_DATAS_LNG
		Inner Join LOADER_STATUS LST
			On SRC.LOADER_STATUS_ID_LOADER_STATUS = LST.ID_LOADER_STATUS
	Set
		TAR.ENTITIES_REF_DATAS_LNG_LABEL = Coalesce(SRC.ENTITIES_REF_DATAS_LNG_LABEL, TAR.ENTITIES_REF_DATAS_LNG_LABEL)
	Where
		LST.LOADER_STATUS_ERRCOUNT = 0
		
		And LST.LOADER_STATUS_BATCH_NUM = batchnum

    ;
End //

Delimiter ;
