本文介绍了Varchar 对 Sum 运算符无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为 Cos 的表,Amt 的数据类型是 Float,示例数据如下所示:
I have a table called Cos and the datatype of Amt is Float and sample data looks like:
Acct Period F_year Amt
Detf 1 2011 Null
Detf 2 2011 Null
Detf 3 2011 1669.57
FTE 1 2011 3205.11
FTE 2 2011 0
FTE 3 2011 Null
我写了一个查询,如:
Select Acct,Period,F_year, Sum(AMT) as Amt
from dbo.Cos
Group By Acct,Period,F_year
Where Amt is not null
但我收到此错误:
Msg 8117, Level 16, State 1, Line 1
Operand data type varchar is invalid for sum operator.
有人可以帮我吗?
推荐答案
尝试这样做:
Select Acct,Period,F_year, Sum(isnull(cast(AMT as float),0)) as Amt
from dbo.Cos
Group By Acct,Period,F_year
这篇关于Varchar 对 Sum 运算符无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!