语法不正确,接近大小写



我正在尝试运行此查询,但是在case和mySum附近得到不正确的语法

Select 
    sum(sumTotal) as mySum 
from
    customertrans 
where 
    DateTime >= DATEPART(HOUR, '6:00')
    case when mySum >25 
    then update TopStatistics 
         set SumDelivery = mySum

你正在尝试的是不可能的。这应该有效:

;with cte (mySum) as 
(
    Select sum(sumTotal) as mySumTopStatistics 
    from customertrans 
    where  DateTime >= DATEPART(HOUR, '6:00')
)
update TopStatistics
set SumDelivery = mySum
where <Search condition with cte table>

不确定您的目标,但我认为您需要 2 个步骤:

Select sum(sumTotal) as mySum,
       case when sum(sumTotal)>25 then 'update' ELSE 'NoUpdate' END AS TopStatistics 
from customertrans 
where  DateTime >= DATEPART(HOUR, '6:00')

然后根据上述输出进行更新。

最新更新