For some reason, the following query which uses the sys.dm_exec_requests DMV and the sys.dm_exec_sql_text DMV fails to compile:
SELECT er.session_id, es.[text]
FROM sys.dm_exec_requests AS er
CROSS APPLY sys.dm_exec_sql_text(er.[sql_handle]) AS es
The query excerpt above is part of a much larger (and more complex) query which fails, because this smaller query will not execute, giving me the syntax error:
Msg 102, Level 15, State 1, Line 3 Incorrect syntax near ‘.’.
The query seems simple enough, yet it looks like the T-SQL parser is balking at the er.sql_handle. I thought this might be an escaping issue and tried er.[sql_handle], but sadly got the same error.
I get this error when running it in the context of a DB in SQL Server 2000 compatibility mode. Try running it under the context of one of the system databases instead.