CREATE TRIGGER TBMDF_NF_B09D FOR TBMDF_NF
ACTIVE BEFORE DELETE POSITION 9
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
  HISTORICO = '';

  IF(OLD.ID > 0) THEN
  BEGIN
    HISTORICO = HISTORICO||'NOTA FISCAL '||OLD.NF_ID || ' EXCLUIDA';
  END

  IF(HISTORICO <> '') THEN
  BEGIN
    EXECUTE PROCEDURE SPI_HISTORICO('TBMDF', OLD.MDF_ID, HISTORICO);
  END
END;