IF EXISTS(SELECT * FROM sysobjects O, sysusers U
          WHERE
            o.name = 'DTULTATU_CSTTEMP' and
            type = 'TR'                 and
            u.uid = o.uid               and
            u.name = USER)
   DROP TRIGGER DTULTATU_CSTTEMP
GO

CREATE TRIGGER DTULTATU_CSTTEMP
ON CSTTEMP
FOR INSERT, UPDATE
AS
BEGIN
   IF NOT (0 = (SELECT COUNT(*) FROM INSERTED)) BEGIN
      UPDATE CSTTEMP
      SET DTULTATUCSTTMP = GETDATE()
      FROM INSERTED
      WHERE (ISNULL(CSTTEMP.NRCSTTEMP,0)  = ISNULL(INSERTED.NRCSTTEMP,0))   AND
            (ISNULL(CSTTEMP.NRSEQUCST,0)  = ISNULL(INSERTED.NRSEQUCST,0));
   END;
END;
GO

-- VERSAO --
EXEC ATUVEROBJ 'ATUALIZA_DADOS_DTPROCESSA','5.03.009';
GO
