ISNUMERIC('07213E71') = 正确吗?

发布于 2024-11-06 23:39:08 字数 139 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

邮友 2024-11-13 23:39:08

07213E71 是一个带有 71 个零的浮点数 7213

您可以使用此 ISNUMERIC(myValue + '.0e0') 来测试整个整数。有点神秘但有效。

另一个测试是双负 myValue NOT LIKE '%[^0-9]%',它只允许数字 0 到 9。ISNUMERIC

还有其他问题,因为这些都返回 1:+< /代码>、<代码>-、<代码>

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: +, -,

帅冕 2024-11-13 23:39:08

挑剔一下:这是一个整数。它相当于7213 * 10 ^ 71

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

雪若未夕 2024-11-13 23:39:08

在文档中它说

当输入表达式计算结果为有效整数、浮点数、货币或小数类型时,ISNUMERIC 返回 1;否则返回 0。返回值 1 保证表达式可以转换为这些数字类型之一。

您的数字也是浮点数(使用指数表示法),因此拥有 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

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

断爱 2024-11-13 23:39:08

我也遇到过同样的问题。 IsNumeric 接受“$、€、+、- 等”作为有效输入,因此 Convert 函数会引发错误。
使用“LIKE”SQL 语句解决了我的问题。我希望它能帮助其他人

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:不要责怪我使用“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

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 :)

甜心小果奶 2024-11-13 23:39:08

无论您使用哪种语言,都必须确保它不调用数据库,然后将值传递给查询。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文