Is the bracket in TSQL strange, expected, or an error?

Try these four SQL commands (I use MS SQL Server Management Studio 2012, connecting to SQLServer 2012 11.0):

select 'hello' from anytable

(select 'hello' from anytable)

select 'hello' from anytable order by 1

(select 'hello' from anytable order by 1)

The first three work just fine. The fourth gives an error:

Msg 156, Level 15, State 1, Line 1 Invalid syntax next to the keyword 'Order'.

Any ideas what is going on?

+4
source share
1 answer

Using parentheses, you indicate that the request is a subquery, and you cannot use the order of operations in the subquery.

+2
source

All Articles