gpt4 book ai didi

sql - Varchar 对 Sum 运算符无效

转载 作者:行者123 更新时间:2023-12-01 06:55:44 24 4
gpt4 key购买 nike

我有一个名为 Cos 的表,Amt 的数据类型是 Float,示例数据如下所示:

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

关于sql - Varchar 对 Sum 运算符无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9673327/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com