ISNUMERIC('07213E71') = 正确吗?
SQL 检测到以下字符串 ISNUMERIC
:
'07213E71'
我相信这是因为 'E' 被归类为数学符号。
但是,我需要确保只有整数值才返回 True。
我该怎么做?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
07213E71
是一个带有 71 个零的浮点数 7213您可以使用此
ISNUMERIC(myValue + '.0e0')
来测试整个整数。有点神秘但有效。另一个测试是双负
myValue NOT LIKE '%[^0-9]%'
,它只允许数字 0 到 9。ISNUMERIC还有其他问题,因为这些都返回 1:
+< /代码>、<代码>-、<代码>
07213E71
is a floating number 7213 with 71 zerosYou 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:
+
,-
,挑剔一下:这是一个整数。它相当于
7213 * 10 ^ 71
。To nitpick: This is a whole integer. It is equivalent to
7213 * 10 ^ 71
.在文档中它说
您的数字也是浮点数(使用指数表示法),因此拥有 ISINTEGER 的唯一方法是在 SQL 上自行定义它。阅读以下链接。
http://classicasp.aspfaq.com/general/what-is -wrong-with-isnumeric.html
额外:
http://www .sqlteam.com/forums/topic.asp?TOPIC_ID=59049
http ://www.tek-tips.com/faqs.cfm?fid=6423
In the documentation it says
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
我也遇到过同样的问题。 IsNumeric 接受“$、€、+、- 等”作为有效输入,因此 Convert 函数会引发错误。
使用“LIKE”SQL 语句解决了我的问题。我希望它能帮助其他人
PS:不要责怪我使用“UnitCode”作为 nvarchar :) 这是一个旧项目:)
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
PS: don't blame me for using "UnitCode" as nvarchar :) It is an old project :)
无论您使用哪种语言,都必须确保它不调用数据库,然后将值传递给查询。 SQL 可能将该值理解为字符串。
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.