Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Non-Numeric test
Fri, Jan 29 2010 12:03 AMPermanent Link

Greg

Hi Tim,

Was good to meet you in Melbourne.

I cannot find a way to simulate the Transact-SQL ISNUMERIC function.

This is Ok and returns 123 ...
SELECT CAST('123' AS integer) FROM AnyTable

However this returns an error where I had hoped it to returned 0 ...
SELECT CAST('a123' AS integer) FROM AnyTable

I read a post saying that DBISAM will return 0 using the same command.

Hope there is a simple way.

Regards

Greg
Fri, Jan 29 2010 3:49 AMPermanent Link

Uli Becker
Greg,

> However this returns an error where I had hoped it to returned 0 ...
> SELECT CAST('a123' AS integer) FROM AnyTable

You get a conversion error here and that can be expected.

How about using a function named ConvertValue:

BEGIN
  DECLARE MyResult INTEGER;
  BEGIN
   SET MyResult = CAST(Value as INTEGER);
  EXCEPTION
   SET MyResult = 0;
  END;
  RETURN MyResult;
END

and use it like this:

select ConvertValue('a123') from mytable.

Regards Uli
Fri, Jan 29 2010 9:39 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Greg,

<< Was good to meet you in Melbourne. >>

Yes, it was a pleasure to meet you and see all of the cool things that
you've done with ElevateDB.

<< I cannot find a way to simulate the Transact-SQL ISNUMERIC function. >>

The best way would be to do what Uli suggested - a custom function that
simply tries the CAST() and then eats any exceptions if the value isn't a
number.

I'll add an enhancement request for a native function, also.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image