SQL Server Home
Incorrect syntax near the keyword 'order' when using parentheses
as By Design
8/23/2010 10:15:28 AM
User(s) can reproduce this bug
When running a query within parentheses with an ORDER BY clause, there is a failure of "Incorrect syntax near the keyword 'order'"
SQL Server 2008 - Standard Edition
Windows XP SP2 Professional
Operating System Language
Steps to Reproduce
(SELECT * FROM msdbms)
Fails with "Incorrect syntax near the keyword 'order'."
(SELECT * FROM msdbms ORDER BY dbms)
Incorrect syntax near the keyword 'order'
No error, should return the results as though there were no parentheses
to post a comment.
Please enter a comment.
on 8/31/2010 at 3:45 PM
This is by design. SELECT * FROM db is a query specification that can be used as either the top level in a relational stream, or somewhere in the middle, passing its selection on to another query specification. The SELECT * FROM db ORDER BY c1 can only be used as a top level select statement and not in the middle of a relational stream because ordering is not a relational operation.
By language convention, parentheses are permitted to delimit query specification (whose result must be relational), but not top level queries such as SELECT...ORDER BY.
See more at http://blogs.msdn.com/b/tsql_language/archive/2004/09/23/233453.aspx
SQL Language Team
to post a workaround.
Please enter a workaround.
on 8/23/2010 at 10:17 AM
Remove the parentheses from the query
© 2014 Microsoft