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

CREATE TRIGGER DTULTATU_TRAB_APURAC_TU
ON TRAB_APURAC_TU
FOR INSERT, UPDATE
AS
BEGIN
   IF NOT (0 = (SELECT COUNT(*) FROM INSERTED)) BEGIN
      UPDATE TRAB_APURAC_TU
      SET DTULTATUAPURATU = GETDATE()
      FROM INSERTED
      WHERE (ISNULL(TRAB_APURAC_TU.CDFILIALAPTU,0)   = ISNULL(INSERTED.CDFILIALAPTU,0))   AND
            (ISNULL(TRAB_APURAC_TU.CDCLIENTEAPTU,0)  = ISNULL(INSERTED.CDCLIENTEAPTU,0))  AND
            (ISNULL(TRAB_APURAC_TU.CDSERVFILIAPTU,0) = ISNULL(INSERTED.CDSERVFILIAPTU,0)) AND
            (ISNULL(TRAB_APURAC_TU.VRPRECUNITAPTU,0) = ISNULL(INSERTED.VRPRECUNITAPTU,0)) AND
            (ISNULL(TRAB_APURAC_TU.NRAPURACTU,0)     = ISNULL(INSERTED.NRAPURACTU,0))     AND
            (ISNULL(TRAB_APURAC_TU.DTAPURACFATTU,0)  = ISNULL(INSERTED.DTAPURACFATTU,0))  AND
            (ISNULL(TRAB_APURAC_TU.CDTURNOTU,0)      = ISNULL(INSERTED.CDTURNOTU,0));
   END;
END;
GO

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