text: USE [QL_DH_GH_ONLINE]
  GO
  CREATE OR ALTER PROCEDURE CNHAPHOPDONG @MAHD CHAR(5), @PTHH FLOAT, @NGAYCAPNHAT DATE 
  AS
  BEGIN TRAN
  	DECLARE @KTRANGAY DATE
  	SET @KTRANGAY = (SELECT NGAYKT FROM HOPDONG WHERE MAHD = @MAHD)
  	UPDATE HOPDONG 
  	SET PHANTRAMHOAHONG = CAST(@PTHH AS NUMERIC(10,2)), NGAYKT = @NGAYCAPNHAT
  	WHERE MAHD = @MAHD
  
  	WAITFOR DELAY '00:00:05'
  	IF (@KTRANGAY > @NGAYCAPNHAT)
  	BEGIN
  		ROLLBACK TRAN
  		RETURN
  	END
  COMMIT TRAN
  GO
  EXEC CNHAPHOPDONG 'HD001', 5, '2021-09-25'