首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sum函数,该如何解决

2012-02-16 
sum函数表中的某一列有数字,有汉字(nvarchar)。如何过滤出数字记录并计算它们的和。[解决办法]怎么过滤?[解

sum函数
表中的某一列有数字,有汉字(nvarchar)。如何过滤出数字记录并计算它们的和。

[解决办法]
怎么过滤?
[解决办法]

SQL code
if object_id('tb') is not null   drop table tbgocreate table tb( id int identity(1,1), col1 varchar(10))goinsert into tb (col1)select '1' union allselect '2' union allselect '你好' union allselect '3'goselect sum(case when isnumeric(col1)=1 then col1 else 0 end) from tbgo/*-----------6(1 行受影响)*/
[解决办法]
是楼上的意思吗?
[解决办法]
select sum(字段) from tb where partindex('%[^0-9]%',字段)=0

热点排行
Bad Request.