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

CREATE TRIGGER DTULTATU_TRAB_APURAC
ON TRAB_APURAC
FOR INSERT, UPDATE
AS
BEGIN
   IF NOT (0 = (SELECT COUNT(*) FROM INSERTED)) BEGIN
      UPDATE TRAB_APURAC
      SET DTULTATUAPURAC = GETDATE()
      FROM INSERTED
      WHERE (ISNULL(TRAB_APURAC.CDCIAAP,0)       = ISNULL(INSERTED.CDCIAAP,0))        AND
            (ISNULL(TRAB_APURAC.NRSEQAPURACAP,0) = ISNULL(INSERTED.NRSEQAPURACAP,0))  AND
            (ISNULL(TRAB_APURAC.CDFILIALAP,0)    = ISNULL(INSERTED.CDFILIALAP,0))     AND
            (ISNULL(TRAB_APURAC.NRAPURACFATAP,0) = ISNULL(INSERTED.NRAPURACFATAP,0));
   END;
END;
GO

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