当前位置: 代码迷 >> Sql Server >> 字符串如果是数字转换成数字,不能转转返回0请教如何写
  详细解决方案

字符串如果是数字转换成数字,不能转转返回0请教如何写

热度:28   发布时间:2016-04-25 00:05:09.0
字符串如果是数字转换成数字,不能转转返回0请问怎么写?
字符串如果是数字转换成数字,不能转转返回0请问怎么写? 
------解决方案--------------------
create table tb(val nvarchar(10))
insert into tb select 'abcd' union all select '324' union all select null
go
select (case when isnumeric(val)!=0 then convert(int,val) else 0 end) from tb
/*
-----------
0
324
0

(3 行受影响)

*/
go
drop table tb
  相关解决方案