Subject | Re: [firebird-support] Definig variable as a domain |
---|---|
Author | Helen Borrie |
Post date | 2010-03-15T00:42:36Z |
At 09:48 AM 15/03/2010, Randall Sell wrote:
declare variable RATE TYPE OF PERCENTAGE;
./heLen
>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.3should be
>
>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;
declare variable RATE TYPE OF PERCENTAGE;
>BEGINThis 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.
> /* 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);
./heLen