How To find slow running queries on SQL 2005

neellotus
Member Posts: 18
Dear All,
I am running following query on SQL2005 Server to find slow running queries :-
SELECT creation_time ,last_execution_time,total_physical_reads,total_logical_reads,total_logical_writes, execution_count, total_worker_time
,total_elapsed_time, total_elapsed_time / execution_count avg_elapsed_time,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
((CASE statement_end_offset WHEN -1 THEN DATALENGTH(st.text)ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) + 1) AS statement_text
FROM sys.dm_exec_query_stats AS qs CROSS APPLY
sys.dm_exec_sql_text(qs.sql_handle) st
ORDER BY total_elapsed_time / execution_count DESC;
But it is showing following error:-
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near '.'.
Basically it showing error at Line 5 and i am writing this "sys.dm_exec_sql_text(qs.sql_handle) st" at Line 5.
Please suggest some solution and tell me where i am doing wrong.
Thanx in advance.
Regards
neel
I am running following query on SQL2005 Server to find slow running queries :-
SELECT creation_time ,last_execution_time,total_physical_reads,total_logical_reads,total_logical_writes, execution_count, total_worker_time
,total_elapsed_time, total_elapsed_time / execution_count avg_elapsed_time,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
((CASE statement_end_offset WHEN -1 THEN DATALENGTH(st.text)ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) + 1) AS statement_text
FROM sys.dm_exec_query_stats AS qs CROSS APPLY
sys.dm_exec_sql_text(qs.sql_handle) st
ORDER BY total_elapsed_time / execution_count DESC;
But it is showing following error:-
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near '.'.
Basically it showing error at Line 5 and i am writing this "sys.dm_exec_sql_text(qs.sql_handle) st" at Line 5.
Please suggest some solution and tell me where i am doing wrong.
Thanx in advance.
Regards
neel
0
Comments
-
I tried your query and in runs without errors on my SQL 2008 R2.
That means this query uses some objects that do not exist in SQL 2005.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Tested the query with SQL 2008 R2 and SQL 2005 - works with bosth servers!Jörg A. Stryk (MVP - Dynamics NAV)
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool0 -
stryk wrote:Tested the query with SQL 2008 R2 and SQL 2005 - works with bosth servers!Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
I was using SQL Server 2005 x64 Enterprise 9.0.5000Jörg A. Stryk (MVP - Dynamics NAV)
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool0 -
This Query ran successfully in the SQL 2008 environment. I think may be it is the issue of memory cache or the memory cursors that doesn't allow proper pre-caching of instructions pipeline.Shipping register software for handling boating accounts.0
-
What are the values that i must be aware to know that are the most significant slow running queries?~~0
-
Depends ...
I actually start to look into queries taking longer than 20 msec "Duration", using more than 1000 "Reads" and are at least executed several dozens of times ...
Than again, it depends ...Jörg A. Stryk (MVP - Dynamics NAV)
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions