SQL IsNumeric 不起作用 [英] SQL IsNumeric not working

查看:32
本文介绍了SQL IsNumeric 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

保留列是一个 varchar,要对其进行求和,我想将其转换为 deciaml.但是下面的SQL给了我一个错误

The reserve column is a varchar, to perform sums on it I want to cast it to a deciaml. But the SQL below gives me an error

select
cast(Reserve as decimal)
from MyReserves

将数据类型 varchar 转换为数字时出错.

Error converting data type varchar to numeric.

我添加了 isnumeric 和 not null 来尝试避免这个错误,但它仍然存在,有什么想法为什么吗?

I added the isnumeric and not null to try and avoid this error but it still persists, any ideas why?

select
cast(Reserve as decimal)
from MyReserves
where isnumeric(Reserve ) = 1
and MyReserves is not null

推荐答案

看来isnumeric有一些问题:

It seems that isnumeric has some Problems:

http://www.sqlhacks.com/Retrieve/Isnumeric-problems(通过互联网档案)

根据那个链接,你可以这样解决:

According to that Link you can solve it like that:

select
cast(Reserve as decimal)
from MyReserves
where MyReserves is not null
and MyReserves * 1 = MyReserves 

这篇关于SQL IsNumeric 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆