ISNUMERIC('07213E71') = True?

2019-01-25 09:08发布

SQL is detecting that the following string ISNUMERIC:

'07213E71'

I believe this is because the 'E' is being classed as a mathmatical symbol.

However, I need to ensure that only values which are whole integers are returned as True.

How can I do this?

5条回答
看我几分像从前
2楼-- · 2019-01-25 09:12

07213E71 is a floating number 7213 with 71 zeros

You can use this ISNUMERIC(myValue + '.0e0') to test for whole integers. Slightly cryptic but works.

Another test is the double negative myValue NOT LIKE '%[^0-9]%' which allows only digits 0 to 9.

ISNUMERIC has other issues in that these all return 1: +, -,

查看更多
男人必须洒脱
3楼-- · 2019-01-25 09:21

To nitpick: This is a whole integer. It is equivalent to 7213 * 10 ^ 71.

查看更多
Lonely孤独者°
4楼-- · 2019-01-25 09:32

I have encountered the same problem. IsNumeric accepts "$, €, +, -, etc" as valid inputs and Convert function throws errors because of this. Using "LIKE" SQL statement fixed my problem. I hope it'll help the others

SELECT UnitCode, UnitGUID, Convert(int, UnitCode) AS IntUnitCode
      FROM [NG_Data].[NG].[T_GLB_Unit]  
     WHERE ISNULL(UnitType,'') <>'Department'
       AND UnitCode NOT LIKE '%[^0-9]%'
  ORDER BY IntUnitCode

PS: don't blame me for using "UnitCode" as nvarchar :) It is an old project :)

查看更多
可以哭但决不认输i
5楼-- · 2019-01-25 09:32

You have to ensure it out of the call to the database, whatever the language you work with, and then pass the value to the query. Probably the SQL is understanding that value as a string.

查看更多
甜甜的少女心
6楼-- · 2019-01-25 09:34

In the documentation it says

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.

Your number is also float (with exponential notation), therefore the only way to have ISINTEGER is to define it yourself on SQL. Read the following link.

http://classicasp.aspfaq.com/general/what-is-wrong-with-isnumeric.html

Extras:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=59049

http://www.tek-tips.com/faqs.cfm?fid=6423

查看更多
登录 后发表回答