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

CREATE TRIGGER DTULTATU_MOVILOTE
ON MOVILOTE
FOR INSERT, UPDATE
AS
BEGIN
   IF NOT (0 = (SELECT COUNT(*) FROM INSERTED)) BEGIN
      UPDATE MOVILOTE
      SET DTULTATUMOVLOTE = GETDATE()
      FROM INSERTED
      WHERE (ISNULL(MOVILOTE.NRMOVILOTE,0)   = ISNULL(INSERTED.NRMOVILOTE,0))   AND
            (ISNULL(MOVILOTE.CDFILIAL,0)     = ISNULL(INSERTED.CDFILIAL,0))     AND
            (ISNULL(MOVILOTE.CDALMOXARIFE,0) = ISNULL(INSERTED.CDALMOXARIFE,0)) AND
            (ISNULL(MOVILOTE.CDLOCALESTOQ,0) = ISNULL(INSERTED.CDLOCALESTOQ,0)) AND
            (ISNULL(MOVILOTE.CDPRODUTO,0)    = ISNULL(INSERTED.CDPRODUTO,0))    AND
            (ISNULL(MOVILOTE.NRLOTEESTQ,0)   = ISNULL(INSERTED.NRLOTEESTQ,0)) AND
            (ISNULL(MOVILOTE.NRSUBLOTE,0)    = ISNULL(INSERTED.NRSUBLOTE,0));
   END;
END;
GO

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