SET TERM ^ ;

CREATE trigger ttbminuta_coleta_b01 for tbminuta_coleta
active before update position 9
AS
declare variable HISTORICO VARCHAR(500);
begin
    HISTORICO = '';

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

    IF(NEW.ESTABELECIMENTO_ID IS DISTINCT FROM OLD.ESTABELECIMENTO_ID) THEN
    BEGIN
        HISTORICO = HISTORICO||' ESTAB: '||OLD.ESTABELECIMENTO_ID||' -> '||NEW.ESTABELECIMENTO_ID;
    END

    IF(NEW.TRANSPORTADORA_ID IS DISTINCT FROM OLD.TRANSPORTADORA_ID) THEN
    BEGIN
        HISTORICO = HISTORICO||' TRANSPORTADORA: '||OLD.TRANSPORTADORA_ID||' -> '||NEW.TRANSPORTADORA_ID;
    END

    IF(HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBMINUTA_COLETA', NEW.ID, HISTORICO);
    END
end
^

SET TERM ; ^