Varchar 对 Sum 运算符无效

Varchar invalid for Sum operator(Varchar 对 Sum 运算符无效)
本文介绍了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 运算符无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!



Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(将每个子标记转换为具有多个分隔符的单列-SQL Server (3))
How can I create a view from more than one table?(如何从多个表创建视图?)
Create calculated value based on calculated value inside previous row(根据前一行内的计算值创建计算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何将表格的前两列堆叠成一列,但也仅将第三列与第一列配对?) - IT屋-程序员软件开发技
Recursive t-sql query(递归 t-sql 查询)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(将月份名称转换为日期/月份编号(问题和答案的组合))