Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 ISNUMERIC function

Author  Topic 

anandc
Starting Member

20 Posts

Posted - 2005-12-13 : 06:51:15
select isnumeric('-') returns 1 indicating valid numeric value, but
select cast('-' as numeric) returns Arithmetic overflow error

Could someone explain this behaviour of SQL server??

Anand

- Anand

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-12-13 : 07:04:03
i'd say it's a bug.
BOL states
quote:

ISNUMERIC returns 1 when the input expression evaluates to a valid integer, floating point number, money or decimal type; otherwise it returns 0. A return value of 1 guarantees that expression can be converted to one of these numeric types.




select isnumeric('-')
, cast ( '-' as int) -- works
, cast ( '-' as money) -- works
, cast ( '-' as float) -- doens't work
, cast ( '-' as numeric(12,2)) -- doens't work
, cast ( '-' as decimal) -- doens't work


Go with the flow & have fun! Else fight the flow
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-13 : 07:04:22
Read this fully
http://aspfaq.com/show.asp?id=2390

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

anandc
Starting Member

20 Posts

Posted - 2005-12-13 : 07:24:17
quote:
Originally posted by madhivanan

Read this fully
http://aspfaq.com/show.asp?id=2390

Madhivanan

Failing to plan is Planning to fail


Hi Madhivanan

I still can't understand why IsNumeric('-') should return 1. If it is like IsNumeric('-4') then its OK. Why IsNumeric of TAB & Carriage Return should return 1 ??

- Anand
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-12-13 : 08:24:32
SQL Server ISNUMERIC will return a 1 for any string it can convert to a number. See the example below for -
declare @x int
select @x ='-'
select [@x] = @x

@x
-----------
0

(1 row(s) affected

quote:
Originally posted by anandc
Hi Madhivanan

I still can't understand why IsNumeric('-') should return 1. If it is like IsNumeric('-4') then its OK. Why IsNumeric of TAB & Carriage Return should return 1 ??

- Anand



CODO ERGO SUM
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-12-13 : 09:02:24
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=59049 for an alternative idea

Kristen
Go to Top of Page
   

- Advertisement -