Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Error in using sys.dm_exec_sql_text

Author  Topic 

rman
Starting Member

2 Posts

Posted - 2011-11-10 : 04:54:20
I am getting error for the following query:


SELECT s2.dbid,
s1.sql_handle,
(SELECT TOP 1 SUBSTRING(s2.text,statement_start_offset / 2+1 ,
( (CASE WHEN statement_end_offset = -1
THEN (LEN(CONVERT(nvarchar(max),s2.text)) * 2)
ELSE statement_end_offset END) - statement_start_offset) / 2+1)) AS sql_statement,
execution_count,
plan_generation_num,
last_execution_time,
total_worker_time,
last_worker_time,
min_worker_time,
max_worker_time,
total_physical_reads,
last_physical_reads,
min_physical_reads,
max_physical_reads,
total_logical_writes,
last_logical_writes,
min_logical_writes,
max_logical_writes
FROM sys.dm_exec_query_stats AS s1
CROSS APPLY sys.dm_exec_sql_text(s1.sql_handle) AS s2
WHERE s2.objectid is null
ORDER BY s1.sql_handle, s1.statement_start_offset, s1.statement_end_offset;


Output
quote:

Msg 102, Level 15, State 1, Line 23
Incorrect syntax near '.'.



Could anyone please tell me why I get this error? I copied the query from msdn site and pasted.

malpashaa
Constraint Violating Yak Guru

264 Posts

Posted - 2011-11-10 : 05:30:10
This is because your sql server instance is either 2000 or less, or COMPATIBILITY_LEVEL is 80 or less.
This query will work on sql server 2005+, and COMPATIBILITY_LEVEL 90+
Go to Top of Page

rman
Starting Member

2 Posts

Posted - 2011-11-10 : 05:48:22
Thanks. It works.
Go to Top of Page
   

- Advertisement -