The first update is a strainght forward one. The second update part can be done by creating an update trigger on tableB or by using OUTPUT clause to retrieve the details as shown:-using OUTPUT variables:-DECLARE @UpdateRows table ( ID int NOT NULL, new_date datetime NOT NULL);UPDATE bSET b.val_holiday=a.val_holidayOUTPUT INSERTED.ID, INSERTED.new_dateINTO @UpdateRowsFROM tableB bINNER JOIN tableA aON a.ID=b.IDAND a.new_date=b.new_dateUPDATE aSET a.field_check_update_if _ok=1FROM tableA aINNER JOIN @UpdateRows uON u.ID=a.IDAND u.new_date=a.new_date
using trigger:-UPDATE bSET b.val_holiday=a.val_holidayFROM tableB bINNER JOIN tableA aON a.ID=b.IDAND a.new_date=b.new_dateCREATE TRIGGER Trig_tableBON tableB AFTER UPDATEASBEGINUPDATE aSET a.field_check_update_if _ok=1FROM tableA aINNER JOIN INSERTED iON i.ID=a.IDAND i.new_date=a.new_dateEND
Please note that the OUTPUT variable method works only in SQL 2005