--测试环境 create table A(ID varchar(10),Gy_ID Varchar(10),Ss_Je Varchar(10),Input varchar(10)) insert into A select '117','19','3','a' union all select '118','19','4','a' union all select '119','19','5','a' union all select '120','19','6','a' union all select '121','19','7','a' go--SQL语句 select sum(convert(int,Ss_Je)) as SumSs_Je from A go --删除表 drop table A/** 结果 SumSs_Je ----------- 25(所影响的行数为 1 行) **/
求总和 Select Sum(Convert(int, Ss_Je)) From Table where 你的条件
Declare @B Varchar(10)
Set @A='3'
Set @B='4'
Select Cast(@A As Int)+Cast(@B As Int)
Declare @B Varchar(10)
Set @A='3'
Set @B='4'
Select Cast(@A As Int)+Cast(@B As Int)
convert(float, Ss_Je)
select Sum(cast(Ss_Je as float)) from 表
set @i = '3'
Select @i
set @j = convert(int, @i)
Select @j
select sum(convert(int,Ss_Je)) from table
有字母的话就不行了
系统会自动转,如果数据不规则,那就有麻烦了。
--测试环境
create table A(ID varchar(10),Gy_ID Varchar(10),Ss_Je Varchar(10),Input varchar(10))
insert into A select '117','19','3','a'
union all select '118','19','4','a'
union all select '119','19','5','a'
union all select '120','19','6','a'
union all select '121','19','7','a'
go--SQL语句
select sum(convert(int,Ss_Je)) as SumSs_Je from A
go
--删除表
drop table A/** 结果
SumSs_Je
-----------
25(所影响的行数为 1 行)
**/
Select Sum(Convert(int, Ss_Je)) From Table where 你的条件