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

CREATE TRIGGER DTULTATU_TRAB_APURAC_GD
ON TRAB_APURAC_GD
FOR INSERT, UPDATE
AS
BEGIN
   IF NOT (0 = (SELECT COUNT(*) FROM INSERTED)) BEGIN
      UPDATE TRAB_APURAC_GD
      SET DTULTATUAPURAGD = GETDATE()
      FROM INSERTED
      WHERE (ISNULL(TRAB_APURAC_GD.CDFILIALAPGD,0)   = ISNULL(INSERTED.CDFILIALAPGD,0))   AND
            (ISNULL(TRAB_APURAC_GD.CDCLIENTEAPGD,0)  = ISNULL(INSERTED.CDCLIENTEAPGD,0))  AND
            (ISNULL(TRAB_APURAC_GD.CDSERVFILIAPGD,0) = ISNULL(INSERTED.CDSERVFILIAPGD,0)) AND
            (ISNULL(TRAB_APURAC_GD.VRPRECUNITAPGD,0) = ISNULL(INSERTED.VRPRECUNITAPGD,0)) AND
            (ISNULL(TRAB_APURAC_GD.NRAPURACGD,0)     = ISNULL(INSERTED.NRAPURACGD,0))     AND
            (ISNULL(TRAB_APURAC_GD.DTAPURACFATGD,0)  = ISNULL(INSERTED.DTAPURACFATGD,0));
   END;
END;
GO

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