ORDER BY子句在视图,内联函数,派生表,子查询和公用表表达式中无效,除非TOP,OFFSET或FOR XML是

问题描述 投票:-5回答:1

我的UPDATE声明在这里:

Update S 
set Status = 6 
Where Status = 5 
  and P_ID in (1, 3) 
  and ID in (Select dbo.T.sID 
             from dbo.T  
             Group By s 
             having Max(TDate) <= @t1 and Max(TDate) >= @t2 
                and sid is not null
             order by Max(TDate))

导致显示错误:

Msg 1033,Level 15,State 1,Line 6 除非还指定了TOP,OFFSET或FOR XML,否则ORDER BY子句在视图,内联函数,派生表,子查询和公用表表达式中无效。

sql sql-server
1个回答
0
投票

order by条款对于内联查询毫无意义。只需从查询中删除order by Max(TDate)部分即可。

Update S 
set Status = 6 
Where Status = 5 
  and P_ID in (1, 3) 
  and ID in (Select dbo.T.sID 
             from dbo.T  
             Group By s 
             having Max(TDate) <= @t1 and Max(TDate) >= @t2 
                and sid is not null )
© www.soinside.com 2019 - 2024. All rights reserved.