SET TERM ^ ;

CREATE trigger ttbroyalties_modelo_b01u for tbroyalties_modelo
active before update position 0
AS
declare variable HISTORICO VARCHAR(500);
begin
    HISTORICO = '';

    IF(NEW.PERCENTUAL IS DISTINCT FROM OLD.PERCENTUAL) THEN
    BEGIN
        HISTORICO = HISTORICO||'PERC: '||OLD.PERCENTUAL||' -> '||NEW.PERCENTUAL||' DO MODELO '||NEW.MODELO_ID;
    END

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

SET TERM ; ^

