Subject | Re: isnumeric() in Firebird |
---|---|
Author | Adam |
Post date | 2006-08-03T00:15:31Z |
--- In firebird-support@yahoogroups.com, <firebird@...> wrote:
numeric or a really negative number otherwise (-2^63 comes to mind).
Firebird is able to cast between varchar and integer, but I think you
will get an exception if it can't occur. You could easily do a stored
procedure that ignored that exception, something like
Create or Alter procedure GetNumericBar
returns
(
Bar BigInt)
as
declare variable bar varchar(25);
begin
for select bar from foo into :bar do
begin
begin
MaxBar = Cast(:Bar as BigInt);
Suspend;
when any do
begin
end
end
end
^
Then you can do:
select max(Bar) from GetNumericBar;
(As always, usual disclaimers, haven't checked syntax blah blah may
not work blah)
Adam
>I'd like
> Here's a table:
>
> Create table foo (
> bar varchar(25)
> .. Other fields ...
> );
>
> bar has some entries that are legal numbers and some that are not.
> to find thesomething else
> largest value for bar considering only those rows where bar is a legal
> number. In some
> databases, I could say this:
>
> Select max(bar) from foo where isnumeric(bar).
>
> It appears that Firebird has no isnumeric built-in. Is there
> I could use?You could certainly write a UDF that returned the number if it was
> A UDF somewhere, maybe?
numeric or a really negative number otherwise (-2^63 comes to mind).
Firebird is able to cast between varchar and integer, but I think you
will get an exception if it can't occur. You could easily do a stored
procedure that ignored that exception, something like
Create or Alter procedure GetNumericBar
returns
(
Bar BigInt)
as
declare variable bar varchar(25);
begin
for select bar from foo into :bar do
begin
begin
MaxBar = Cast(:Bar as BigInt);
Suspend;
when any do
begin
end
end
end
^
Then you can do:
select max(Bar) from GetNumericBar;
(As always, usual disclaimers, haven't checked syntax blah blah may
not work blah)
Adam