Subject Re: [firebird-support] Definig variable as a domain
Author Randall Sell
Thanx Helen. Can you clarify what is the difference between

DECLARE VARIABLE RATE PERCENTAGE;
and
declare variable RATE TYPE OF PERCENTAGE;

I will try your approach.

As for the actual calculation itself, I should have mentioned that the error happens in the SELECT query attempting to stick a value into :RATE

But why would it work when called directly, vs a SELECT that runs the same proceudre via a COMPUTED BY column? Seems more to me to be a bug with COMPUTED columns.

-randall





________________________________
From: Helen Borrie <helebor@...>
To: firebird-support@yahoogroups.com
Sent: Mon, 15 March, 2010 11:42:36 AM
Subject: Re: [firebird-support] Definig variable as a domain


At 09:48 AM 15/03/2010, Randall Sell wrote:
>Hi, I am getting an error and scratching my head as to why. Perhaps someone can clarify if this is a known FB bug, or my lack of understanding. .. Using FB 2.1.3
>
>I've defined the following domain:
>
>CREATE DOMAIN PERCENTAGE
> AS Double precision
> CHECK ((value is null) or ((value >= 0) and (value <= 100)))
>;
>
>And I have this procedure:
>
>SET TERM ^ ;
>ALTER PROCEDURE P_TAX_AMOUNT (
> AMOUNT MONEY,
> TAXRATEID FOREIGNKEY )
>RETURNS (
> TAXAMOUNT MONEY )
>AS
>DECLARE VARIABLE RATE PERCENTAGE;

should be
declare variable RATE TYPE OF PERCENTAGE;

>BEGIN
> /* given an amount and a tax rate id, calculates the tax amount */
> SELECT RATE FROM V_TAXRATE
> WHERE TAXRATEID = :TAXRATEID
> INTO :RATE;
>
> IF (RATE IS NULL) THEN
> TAXAMOUNT = 0;
> TAXAMOUNT = (CAST(RATE AS DOUBLE PRECISION) / 100) * CAST(AMOUNT AS DOUBLE PRECISION);

This might be a bit dodgy, too. RATE is already DOUBLE PRECISION so it shouldn't be cast. Don't know about the data type of your MONEY domain but at least you're going to have to take some care with how you mix up doubles, integers and fixed numerics.

./heLen







[Non-text portions of this message have been removed]