我有以下T-SQL语句:
select top 10 value1 from table1 where condition1 = 12345
结果:
5449.0
228231.0
0.0
3128.0
6560.0
4541.0
2119.0
0.0
0.0
4183.0
数据类型value1 =" [char](20)COLLATE Latin1_General_CS_AS NULL"
请注意,每个结果行有20个字符,即" 5449.0 ______________"充满了空间。
我想总结所有这些专栏。如何将这些值转换为可求和的数据类型?
答案 0 :(得分:0)
使用强制转换或转换:
-- for demo
declare @v char(20)
set @v = '228231.9 '
-- real magic
select cast(@v as real)
所以这是您案例中的选择:
select cast(value1 as real) from table1 where condition1 = 12345
select sum(cast(value1 as real)) from table1 where condition1 = 12345