使用带有 ISNUMERIC 的派生表进行查询会导致转换失败(varchar 到 int)
这是一个示例查询:
DECLARE @table table (loc varchar(10))
INSERT INTO @table VALUES
('134a'), ('123'), ('abc'), ('124')
SELECT *
FROM (
SELECT * FROM @table WHERE ISNUMERIC(loc) = 1
) as a
WHERE CAST(loc as INT) BETWEEN 100 AND 200
如果我有一些 varchar 值,并且我在查询的派生表中使用 ISNUMERIC
将它们限制为数值,为什么会导致转换错误?:
将 varchar 值“134a”转换为数据类型 int 时转换失败。
有办法解决这个问题吗?
Here's an example query:
DECLARE @table table (loc varchar(10))
INSERT INTO @table VALUES
('134a'), ('123'), ('abc'), ('124')
SELECT *
FROM (
SELECT * FROM @table WHERE ISNUMERIC(loc) = 1
) as a
WHERE CAST(loc as INT) BETWEEN 100 AND 200
If I have some varchar values and I limit them to numeric values using ISNUMERIC
in a derived table in the query, why does it result in a conversion error?:
Conversion failed when converting the varchar value '134a' to data type int.
Is there a way around this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WHERE
子句首先执行。尝试:The
WHERE
clause executes first. Try: