ALTER TABLE TBROYALTIES_MODELO
    ADD VALOR_UNITARIO NUMERIC(15,2) DEFAULT 0 NOT NULL;
	
SET TERM ^ ;

CREATE OR ALTER 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(NEW.VALOR_UNITARIO IS DISTINCT FROM OLD.VALOR_UNITARIO) THEN
    BEGIN
        HISTORICO = HISTORICO||'VR.UNIT: '||OLD.VALOR_UNITARIO||' -> '||NEW.VALOR_UNITARIO||' DO MODELO '||NEW.MODELO_ID;
    END

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

SET TERM ; ^

	