读书人

字符串如果是数字转换成数字不能转转

发布时间: 2013-01-05 15:20:40 作者: rapoo

字符串如果是数字转换成数字,不能转转返回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

读书人网 >SQL Server

热点推荐