IF EXISTS (SELECT * FROM SYS.TRIGGERS WHERE NAME = 'TRG_INTEGRA_ULTRAFARMA_LOG_STATUS')
BEGIN
	DROP TRIGGER TRG_INTEGRA_ULTRAFARMA_LOG_STATUS
END

GO

CREATE TRIGGER TRG_INTEGRA_ULTRAFARMA_LOG_STATUS ON INTEGRA_ULTRAFARMA_LOG 
	AFTER INSERT, UPDATE
AS
BEGIN
	IF NOT UPDATE (STATUS)
		RETURN;

	UPDATE U
	SET
		STATUS=0
	FROM
		INTEGRA_ULTRAFARMA_LOG U
		join INSERTED I ON
		U.CD_CTR =I.CD_CTR
	WHERE 
		I.STATUS=2;

END

GO