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

CREATE TRIGGER DTULTATU_TRAB_APURAC_EQ
ON TRAB_APURAC_EQ
FOR INSERT, UPDATE
AS
BEGIN
   IF NOT (0 = (SELECT COUNT(*) FROM INSERTED)) BEGIN
      UPDATE TRAB_APURAC_EQ
      SET DTULTATUAPURAEQ = GETDATE()
      FROM INSERTED
      WHERE (ISNULL(TRAB_APURAC_EQ.CDFILIALAPEQ,0)   = ISNULL(INSERTED.CDFILIALAPEQ,0))   AND
            (ISNULL(TRAB_APURAC_EQ.CDCLIENTEAPEQ,0)  = ISNULL(INSERTED.CDCLIENTEAPEQ,0))  AND
            (ISNULL(TRAB_APURAC_EQ.CDSERVFILIAPEQ,0) = ISNULL(INSERTED.CDSERVFILIAPEQ,0)) AND
            (ISNULL(TRAB_APURAC_EQ.VRPRECUNITAPEQ,0) = ISNULL(INSERTED.VRPRECUNITAPEQ,0)) AND
            (ISNULL(TRAB_APURAC_EQ.NRAPURACEQ,0)     = ISNULL(INSERTED.NRAPURACEQ,0))     AND
            (ISNULL(TRAB_APURAC_EQ.DTAPURACFATEQ,0)  = ISNULL(INSERTED.DTAPURACFATEQ,0))  AND
            (ISNULL(TRAB_APURAC_EQ.CDSERVPREQUI,0)   = ISNULL(INSERTED.CDSERVPREQUI,0));
   END;
END;
GO

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