Subject | Re: [firebird-support] Re: Query question |
---|---|
Author | Robert martin |
Post date | 2005-01-21T00:39:29Z |
Hi Adam
I really don't want to use External functions if I can avoid it. Just
to avoid problems with user installs etc. I have come up with the
following solution....
Select Amount, case when (Amount < 0) then 0 - Amount else Amount end
From MyTable
Order By 2
Which seems to do the trick.
Thanks for your suggestion anyway :)
Rob
Adam wrote:
I really don't want to use External functions if I can avoid it. Just
to avoid problems with user installs etc. I have come up with the
following solution....
Select Amount, case when (Amount < 0) then 0 - Amount else Amount end
From MyTable
Order By 2
Which seems to do the trick.
Thanks for your suggestion anyway :)
Rob
Adam wrote:
>
> This uses a UDF, but you don't have to write or distribute anything,
> the UDF comes pre-installed in Firebird, the following command will
> declare it for you.
>
> DECLARE EXTERNAL FUNCTION abs
> DOUBLE PRECISION
> RETURNS DOUBLE PRECISION BY VALUE
> ENTRY_POINT 'IB_UDF_abs' MODULE_NAME 'ib_udf';
>
> Then you should be able to use
>
> select MyCol
> from MyTable
> order by abs(MyCol);
>
> In theory you could create your own abs function using a simple
> stored procedure, something like.
>
> if InValue < 0 then
> begin
> OutValue = -1 * InValue;
> end
> else
> begin
> OutValue = InValue;
> end
>
> and may even be able to remove the UDF altogether, though IMO this is
> a waste of time because the work is already done for you.
>
> Adam
>