SET TERM ^ ;

CREATE OR ALTER TRIGGER CENTRAL_SERVICOS_NOTIF_FINALIZA FOR CENTRAL_SERVICOS_NOTIFICACOES
ACTIVE BEFORE INSERT OR UPDATE POSITION 3
AS
DECLARE VARIABLE I_TEMP INTEGER;
BEGIN
  IF ((NEW.FINALIZADO IS NOT NULL) AND
      (OLD.FINALIZADO IS DISTINCT FROM NEW.FINALIZADO)) THEN
  BEGIN
    SELECT COD_USUARIO
    FROM FUNCAO_COD_USUARIO
    INTO :I_TEMP;

    NEW.COD_USUARIO_FINALIZADO = :I_TEMP;
    NEW.DATA_FINALIZADO = CURRENT_TIMESTAMP;
  END
END
^
SET TERM ; ^