SET TERM ^ ;

CREATE OR ALTER TRIGGER SETORES_BUFFER_BU_DTEXEC FOR SETORES_BUFFER
ACTIVE BEFORE UPDATE POSITION 0
AS
BEGIN
  /* Trigger text */
  IF ((NEW.PROCESSADO = 'T')
      AND (OLD.PROCESSADO = 'F')
      AND (NEW.DATAHORA_EXECUCAO IS NULL)) THEN
    NEW.DATAHORA_EXECUCAO = CURRENT_TIMESTAMP;
END^

SET TERM ; ^

COMMENT ON TRIGGER SETORES_BUFFER_BU_DTEXEC IS '07.04.21: Vitorino - Identificar quando foi executado o buffer';