select sum(cast(amount as numeric(20,5)) from table where ISNUMERIC(amount )=1
alter tablename alter column amount decimal(20,5)
select sum(amount) from tablename
上面都不行的话,笨一点的方法: select cast(amount as decimal(14,4)) as amount into #tmp_table from tablename select sum(amount) from #tmp_table
數據裡面含有 '23,123.23' 和 'NULL' 值,請問如何處理
若'23,123.23' 理解为23123.23,则可以这样转:convert(numeric(20,5),replace(amount,',',''))。至于'NULL',可以采用条件过滤:where amount is not nullselect sum(convert(numeric(20,5),replace(amount,',',''))) from yourtable where amount is not null
select cast(amount as decimal(14,4)) as amount into #tmp_table from tablename
select sum(amount) from #tmp_table
from yourtable where amount is not null