UPDATE HMUAYENE SET IPTAL=1 WHERE
 NOT EXISTS(SELECT HMUAYENEID FROM HMUAYENEISL WHERE  HMUAYENE.HMUAYENEID=HMUAYENEISL.HMUAYENEID) AND 
 NOT EXISTS(SELECT HMUAYENEID FROM HYATIS WHERE  HMUAYENE.HMUAYENEID=HYATIS.HMUAYENEID) AND 
 IPTAL=0 AND HMTARIH>'2016-05-01'
GO 