Delimiter //
/**
    In batchnum Int : num du lot
*/
Drop Procedure if exists LOADER_RECLAIMS_DETAILS_UPDATE//
Create Procedure LOADER_RECLAIMS_DETAILS_UPDATE (
    In batchnum int
)
Begin

        Update RECLAIMS_DETAILS tar
			Inner Join LOADER_RECLAIMS src  
				on tar.ID_RECLAIMS_DETAILS = src.RECLAIMS_DETAILS_PREV_RECLAIM
			Inner Join LOADER_STATUS lst  
				On src.LOADER_STATUS_ID_LOADER_STATUS = lst.ID_LOADER_STATUS
			
		Set
			tar.RECLAIMS_DETAILS_IS_ACTIVE = 0
			, tar.RECLAIMS_DETAILS_LAST_UPDATE = now()
        Where 
            lst.LOADER_STATUS_ERRCOUNT = 0  
            And lst.LOADER_STATUS_BATCH_NUM =  batchnum
			-- on maj les détail que 
			-- --> pour les reclamation à actualiser (src.ID_RECLAIMS <> null)
            and src.ID_RECLAIMS Is Not Null
        ;
End //

Delimiter ;
