0

我正在使用以下查询在 SQL Server 2008 上检查它,我得到的错误是

消息 102,级别 15,状态 1,第 13 行 '.' 附近的语法不正确。

询问:

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

第 13 行是

FROM sys.dm_exec_query_stats AS qs

不知道是什么问题

我的 SQL Server 版本是:

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

1 回答 1

3

您的数据库处于 2000 兼容模式。执行此操作后,您的查询将起作用:

ALTER DATABASE YourDatabase SET COMPATIBILITY_LEVEL = 100;

请注意,它可能出于某种原因处于 80 模式,但通常这只是升级或迁移过程中被遗忘的步骤。

于 2012-07-06T13:54:20.477 回答