聚合可能不会出现在UPDATE语句的设置列表中。如果使用列名更新 [英] An aggregate may not appear in the set list of an UPDATE statement. If update with Column Names
本文介绍了聚合可能不会出现在UPDATE语句的设置列表中。如果使用列名更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
运行时出现错误
聚合可能不会出现在UPDATE语句的设置列表中。
An aggregate may not appear in the set list of an UPDATE statement.
代码:
update CheckInCheckOut
set CountHours = (select ROUND(SUM(DATEDIFF(ss,CheckIn,CheckOut) / 60.0 / 60.0), 2))
where UserId_Fk = 3
当我将其写为以下内容时,此查询有效:
This query works when I write it as:
update CheckInCheckOut
set CountHours = ROUND(SUM(DATEDIFF(ss, '2014-05-15 00:23:04.580', '2014-05-15 00:25:04.580') / 60.0 / 60.0), 2)
CheckIn datetime,
CheckOut datetime
示例值得赞赏。
推荐答案
尝试为此声明一个变量:
Try declare a variable for the purpose:
DECLARE @Result Decimal(18, 0)
SET @Result = ROUND(SUM(DATEDIFF(ss,'2014-05-15 00:23:04.580','2014-05-15 00:25:04.580') / 60.0 / 60.0), 2)
update CheckInCheckOut
set CountHours= @Result
where UserId_Fk=3
这篇关于聚合可能不会出现在UPDATE语句的设置列表中。如果使用列名更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文