在运行中,出错
聚合可能不会出现在UPDATE语句的集合列表中。
代码:
update CheckInCheckOut
set CountHours = (select ROUND(SUM(DATEDIFF(ss,CheckIn,CheckOut) / 60.0 / 60.0), 2))
where UserId_Fk = 3
当我将其写为:
时,此查询有效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
示例将不胜感激。
答案 0 :(得分:1)
尝试为此目的声明变量:
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