if object_id('tb') is not null drop table tb go create table tb ( id int identity(1,1), col1 varchar(10) ) go insert into tb (col1) select '1' union all select '2' union all select '你好' union all select '3' go select sum(case when isnumeric(col1)=1 then col1 else 0 end) from tb go /* ----------- 6(1 行受影响) */
select sum(字段) from tb where partindex('%[^0-9]%',字段)=0
if object_id('tb') is not null
drop table tb
go
create table tb
(
id int identity(1,1),
col1 varchar(10)
)
go
insert into tb (col1)
select '1' union all
select '2' union all
select '你好' union all
select '3'
go
select sum(case when isnumeric(col1)=1 then col1 else 0 end) from tb
go
/*
-----------
6(1 行受影响)
*/