ALTER TABLE TBCANAL_VENDAS
ADD CCUSTO VARCHAR(10) CHARACTER SET UTF8
DEFAULT '' 
COLLATE UTF8^

ALTER TABLE TBCANAL_VENDAS
ADD CLASSIFICACAO_FINANCEIRA VARCHAR(10) CHARACTER SET UTF8
DEFAULT '' 
COLLATE UTF8^

CREATE OR ALTER TRIGGER TTBCANAL_VENDAS_B01U FOR TBCANAL_VENDAS
ACTIVE BEFORE UPDATE POSITION 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(5000);
BEGIN

    HISTORICO = '';

    IF (OLD.DESCRICAO <> NEW.DESCRICAO) THEN
    BEGIN
        HISTORICO = HISTORICO||' DESC:'||OLD.DESCRICAO||'->'||NEW.DESCRICAO;
    END            

    IF (OLD.CCUSTO <> NEW.CCUSTO) THEN
    BEGIN
        HISTORICO = HISTORICO||' CCUSTO:'||OLD.CCUSTO||'->'||NEW.CCUSTO;
    END

    IF (OLD.CLASSIFICACAO_FINANCEIRA <> NEW.CLASSIFICACAO_FINANCEIRA) THEN
    BEGIN
        HISTORICO = HISTORICO||' CLASS:'||OLD.CLASSIFICACAO_FINANCEIRA||'->'||NEW.CLASSIFICACAO_FINANCEIRA;
    END

    IF (HISTORICO <> '') THEN
    BEGIN
       HISTORICO = 'REGISTRO ALTERADO:'||HISTORICO;
       EXECUTE PROCEDURE SPI_HISTORICO('TBCANAL_VENDAS', OLD.ID, FN_ELIPSE(HISTORICO, 500));
    END
END^