0
我有一個遊標聲明的位置:爲什麼在這個遊標聲明上沒有括號?
declare c cursor
for (select ProductName, ListPrice
from Products
where ListPrice > 700)
但如果我添加一個order by
條款,我得到一個錯誤:
declare c cursor
for (select ProductName, ListPrice
from Products
where ListPrice > 700
order by ListPrice desc)
錯誤:Incorrect syntax near the keyword 'order'.
但錯誤消失,如果我拿掉括號:
declare c cursor
for select ProductName, ListPrice
from Products
where ListPrice > 700
order by ListPrice desc
也許我對於括號在SQL Server中做了些什麼不太清楚。是什麼賦予了?爲什麼order by
子句以這種方式與圓括號交互?
SQL Server不喜歡子查詢中的order by(除非你也有'top')。我想它將括號內的查詢解釋爲一個子查詢,因爲不需要這些parens。 – 2015-03-03 01:44:36
這很有道理。你應該把答案放在一個答案中,以便我可以給你信用。 – Indigenuity 2015-03-03 02:09:48