TSCAmerica.com
TSCAmerica.com

Reputation: 5377

SQL Server 2008 Query throwing error

I am using following query to check it on SQL Server 2008, the error I am getting is

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

Query:

SELECT total_worker_time/execution_count AS AvgCPU  
, total_worker_time AS TotalCPU
, total_elapsed_time/execution_count AS AvgDuration  
, total_elapsed_time AS TotalDuration  
, (total_logical_reads+total_physical_reads)/execution_count AS AvgReads 
, (total_logical_reads+total_physical_reads) AS TotalReads
, execution_count   
, SUBSTRING
    (
      st.TEXT, (qs.statement_start_offset/2)+1, 
      (
        (
           CASE qs.statement_end_offset 
             WHEN -1 THEN datalength(st.TEXT)  
             ELSE qs.statement_end_offset  
             END - qs.statement_start_offset
         )/2
       ) + 1
    ) AS txt  
, query_plan
FROM sys.dm_exec_query_stats AS qs  
cross apply sys.dm_exec_sql_text(qs.sql_handle) AS st  
cross apply sys.dm_exec_query_plan (qs.plan_handle) AS qp 
ORDER BY 1 DESC

Line number 13 is

FROM sys.dm_exec_query_stats AS qs

not sure what the issue is

My SQL Server version is:

Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (X64)   
Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7600)

Upvotes: 0

Views: 235

Answers (1)

anon
anon

Reputation:

Your database is in 2000 compatibility mode. Once you do this, your query will work:

ALTER DATABASE YourDatabase SET COMPATIBILITY_LEVEL = 100;

Note that it may be in 80 mode for a reason, but usually this is just a forgotten step during an upgrade or migration.

Upvotes: 3

Related Questions