判断字段是否为数字

jidianxueyuan 2009-11-12 11:06:24
判断字段是否为数字 是数字把数据返回,不是的话返回0
...全文
343 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangyn77 2009-11-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wufeng4552 的回复:]
SQL codeselectcasewhenISNUMERIC(col)=1then colelse0endfrom tb
[/Quote]
支持
fwacky 2009-11-12
  • 打赏
  • 举报
回复

select case when isnumeric(col) = 1 then 1 else 0 end
from
(
select 'aaa' as col union all
select '111'union all
select '4'
) a
===
=======
0
1
1
--两个都行!
fwacky 2009-11-12
  • 打赏
  • 举报
回复

select case when col like '%[0-9]%' then 1 else 0 end
from
(
select 'aaa' as col union all
select '111'union all
select '4'
) a

=======
0
1
1
忆轩辕 2009-11-12
  • 打赏
  • 举报
回复
看成变量了..orz



select case when col like '%[0-9]%' then 1 else 0 end from tb

--竟然忘了还有isnumeric........

chuifengde 2009-11-12
  • 打赏
  • 举报
回复
or
select isnull(nullif(isnumeric([Field]),1),[Field])
from [Table]
--小F-- 2009-11-12
  • 打赏
  • 举报
回复
select 
case when isnumeric(col)=1 then col else 0 end
from
tb
忆轩辕 2009-11-12
  • 打赏
  • 举报
回复
if @a like '%[0-9]%'
SQL77 2009-11-12
  • 打赏
  • 举报
回复
SELECT CASE WHEN ISNUMERIC(COL)=0 THEN 0 ELSE COL END AS COL FROM TB
chuifengde 2009-11-12
  • 打赏
  • 举报
回复
select case when isnumeric([Field])=1 then [Field] else 0 end 
from [Table]
水族杰纶 2009-11-12
  • 打赏
  • 举报
回复

select case when ISNUMERIC(col)=1 then col else 0 end
from tb
laker_914 2009-11-12
  • 打赏
  • 举报
回复

isnumeric()
zhengduan964532 2009-11-12
  • 打赏
  • 举报
回复
SELECT CASE WHEN ISNUMERIC(TYPE)=0 THEN 1 ELSE 0 END 
FROM A
chen8410 2009-11-12
  • 打赏
  • 举报
回复
ISNUMERIC ( expression )
确定表达式是否为有效的数值类型。

如果输入表达式的计算值为有效的整数、浮点数、money 或 decimal 类型时,ISNUMERIC 返回 1;否则返回 0。返回值为 1 时,指示可将 expression 至少转换为上述数值类型中的一种。
wly0502 2009-11-12
  • 打赏
  • 举报
回复
SQL code

select z_ww from tbl_user where patindex('%[0-9]%',zww)>0
ChinaJiaBing 2009-11-12
  • 打赏
  • 举报
回复

---返回1或0(数据型)
select isnumeric(1)
--返回1或0(表示是不是日期型)
select isdate(1)
忆轩辕 2009-11-12
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 mjf_2008 的回复:]
SQL codeselectcasewhen collike'%[0-9]%'then1else0endfrom
(select'aaa'as colunionallselect'111'unionallselect'4'unionallselect'4aaa'
) a

--这个方法貌似不行吧。。
[/Quote]

不要只顾拿了代码直接执行,这句改一个地方就可以实现了
luoyoumou 2009-11-12
  • 打赏
  • 举报
回复
--判断字段是否为数字 是数字把数据返回,不是的话返回0
drop table tb;
create table tb(colname varchar(10));
insert into tb(colname)
select
'luoyoumou' union all select
'123' union all select
'123ab4';

select (case when isnumeric(colname)=1 then colname else 0 end) as is_num
from tb;
--------------------------------------------------------
0
123
0
luoyoumou 2009-11-12
  • 打赏
  • 举报
回复

--判断字段是否为数字 是数字把数据返回,不是的话返回0
select (case when isnumeric(colname)=1 the colname else 0 end) as is_num
from tb;
luoyoumou 2009-11-12
  • 打赏
  • 举报
回复
-- isnumeric() 正解!
mjf_2008 2009-11-12
  • 打赏
  • 举报
回复

select case when col like '%[0-9]%' then 1 else 0 end
from
(
select 'aaa' as col union all
select '111'union all
select '4' union all
select '4aaa'
) a


--这个方法貌似不行吧。。

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧