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

CREATE TRIGGER DTULTATU_PARGERALSUV
ON PARGERALSUV
FOR INSERT, UPDATE, DELETE
AS
BEGIN
   IF (0 = (SELECT COUNT(*) FROM INSERTED)) BEGIN
      INSERT INTO DELETECACHE (NMTABLECACHE, CDFILICACHE, DSKEYCACHE, DTULTATUCACH)
			      (SELECT 'PARGERALSUV', null, 'NRPARGERALSUV='+CONVERT(VARCHAR, NRPARGERALSUV)+ ';', GETDATE() FROM DELETED)
   END
   ELSE BEGIN
      UPDATE PARGERALSUV
      SET DTULTATUPAGESUV = GETDATE()
      FROM INSERTED
      WHERE (ISNULL(PARGERALSUV.NRPARGERALSUV,0) = ISNULL(INSERTED.NRPARGERALSUV,0)) AND
            (ISNULL(PARGERALSUV.CDFILSOLISUP,0) = ISNULL(INSERTED.CDFILSOLISUP,0)) AND
            (ISNULL(PARGERALSUV.CDGRUPPRODDESP,0) = ISNULL(INSERTED.CDGRUPPRODDESP,0)) AND
            (ISNULL(PARGERALSUV.CDTIPOSUPRIDEVO,0) = ISNULL(INSERTED.CDTIPOSUPRIDEVO,0)) AND
            (ISNULL(PARGERALSUV.CDTIPOSUPRIREEM,0) = ISNULL(INSERTED.CDTIPOSUPRIREEM,0)) AND
            (ISNULL(PARGERALSUV.CDSERIEENTR,0) = ISNULL(INSERTED.CDSERIEENTR,0)) AND
            (ISNULL(PARGERALSUV.CDSUBGRPRODDESP,0) = ISNULL(INSERTED.CDSUBGRPRODDESP,0)) AND
            (ISNULL(PARGERALSUV.IDENTRSAIDOPEN,0) = ISNULL(INSERTED.IDENTRSAIDOPEN,0)) AND
            (ISNULL(PARGERALSUV.CDTIPOOPERPAG,0) = ISNULL(INSERTED.CDTIPOOPERPAG,0)) AND
            (ISNULL(PARGERALSUV.IDENTRSAIDOPSA,0) = ISNULL(INSERTED.IDENTRSAIDOPSA,0)) AND
            (ISNULL(PARGERALSUV.CDTIPOOPERREC,0) = ISNULL(INSERTED.CDTIPOOPERREC,0)) AND
            (ISNULL(PARGERALSUV.DSSMTPEMAIL,0) = ISNULL(INSERTED.DSSMTPEMAIL,0)) AND
            (ISNULL(PARGERALSUV.DSEMAILORIGEM,0) = ISNULL(INSERTED.DSEMAILORIGEM,0)) AND
            (ISNULL(PARGERALSUV.CDSENHAEMAIL,0) = ISNULL(INSERTED.CDSENHAEMAIL,0));
   END;
END;
GO

-- VERSAO --
EXEC ATUVEROBJ 'DTULTATU_PARGERALSUV','5.11.000';
GO
