SET TERM ^ ;

CREATE OR ALTER trigger tbcor_b03u for tbcor
active before update position 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

  HISTORICO = '';

  if (OLD.PERFIL IS NOT NULL AND NEW.PERFIL = '') then
       BEGIN
       HISTORICO = HISTORICO||' COR EXCLUIDA: '||OLD.CODIGO||' - '||OLD.DESCRICAO;
       END

  IF(HISTORICO <> '') THEN
  BEGIN
    EXECUTE PROCEDURE SPI_HISTORICO('TBPERFIL', (SELECT FIRST 1 P.CONTROLE FROM TBPERFIL P WHERE P.ID = OLD.PERFIL AND P.TABELA = 'COR'), HISTORICO);
  END
END
^

SET TERM ; ^

