Subject Re: [firebird-support] Definig variable as a domain
Author Randall Sell
FWIW, changing the declaration and sticking in "TYPE OF" does fix the problem. But creates a HUGE problem for me. We have variables declared all over the place using my incorrect syntax. So I need to understand the ramifications to know if all of them need adjusting.

cheers,
-randall





________________________________
From: Randall Sell <randallsell@...>
To: firebird-support@yahoogroups.com
Sent: Mon, 15 March, 2010 5:13:11 PM
Subject: Re: [firebird-support] Definig variable as a domain


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@iinet. net.au>
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]







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