SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Identfying long running queries in SQL 2000.


Identfying long running queries in SQL 2000.

Author
Message
CH&HU-1021641
CH&HU-1021641
Old Hand
Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)

Group: General Forum Members
Points: 311 Visits: 191
Dear all,

We are using SQL Server 2005 for production and the database compatability level is kept for 80 not 90. I have a qery for
finding the long running queries which supports on SQL 2005 not 2000 database. Its throwing error when i run the query
to identify the long running queries.

Query :

select top 50
qs.total_worker_time / execution_count as avg_worker_time,
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 statement_text,
*
from
sys.dm_exec_query_stats as qs
cross apply sys.dm_exec_sql_text(qs.sql_handle) as st
order by
avg_worker_time desc

ERROR :
Server: Msg 170, Level 15, State 1, Line 11
Line 11: Incorrect syntax near 'apply'.


Can anyone please have a look into this to work fine for 2000 compatibility databases.

Or else anyone please provide me the query for identifying the long running queries.


Thanks,
CH&HU.
Mohit K. Gupta
Mohit K. Gupta
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3206 Visits: 1089
Try ...

SELECT TOP 50 qs.total_worker_time / execution_count as avg_worker_time,
(SELECT 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)
FROM sys.dm_exec_sql_text(qs.sql_handle) AS ST) AS statement_text,
*
FROM sys.dm_exec_query_stats AS qs
ORDER BY avg_worker_time DESC



Thanks.

EDIT: Forgot to format the query so it was hard to read ... Sorry.

---

Mohit K. Gupta, MCITP: Database Administrator (2005), My Blog, Twitter: @SQLCAN.
Microsoft FTE - SQL Server PFE

* Some time its the search that counts, not the finding...
* I didn't think so, but if I was wrong, I was wrong. I'd rather do something, and make a mistake than be frightened and be doing nothing. Smooooth


How to ask for help .. Read Best Practices here.
CH&HU-1021641
CH&HU-1021641
Old Hand
Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)Old Hand (311 reputation)

Group: General Forum Members
Points: 311 Visits: 191
--------------------------------------------------


Error : Server: Msg 170, Level 15, State 1, Line 17
Line 17: Incorrect syntax near '.'.





Thanks,
CH&HU
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)SSC Guru (99K reputation)

Group: General Forum Members
Points: 99567 Visits: 33014
If the database is running in 80 compatibility mode, you won't be able to run 90 type queries, which include using the CROSS APPLY query.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Mohit K. Gupta
Mohit K. Gupta
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3206 Visits: 1089
Urg sorry; that wouldn't work because the function returns a table which was not supported in SQL 2000.

You can run that query in a database that is 90 and it will return the SQL Statements to you. Please note this is instance wide and not database based.

When I run it on masters database I don't just get master database statements I get statements from all server statements.

Thanks.

Mohit.

---

Mohit K. Gupta, MCITP: Database Administrator (2005), My Blog, Twitter: @SQLCAN.
Microsoft FTE - SQL Server PFE

* Some time its the search that counts, not the finding...
* I didn't think so, but if I was wrong, I was wrong. I'd rather do something, and make a mistake than be frightened and be doing nothing. Smooooth


How to ask for help .. Read Best Practices here.
umar iqbal
umar iqbal
SSC-Addicted
SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)SSC-Addicted (456 reputation)

Group: General Forum Members
Points: 456 Visits: 395
dbcc opentran will tell for oldest open transaction.


look for last_batch and status

then runn dbcc inputbuffer(spid)
to see whats it running.

Crazy Alien

Umar Iqbal
bkriszio
bkriszio
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 45
If your problem is a database with compatibility level 80 on an SQL Server 2005, just run the query from some other database on that server which has compatibility level 90, e.g. tempdb.
mvinokur
mvinokur
SSC Rookie
SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)

Group: General Forum Members
Points: 44 Visits: 31
I get the following error:

Msg 170, Level 15, State 1, Line 9
Line 9: Incorrect syntax near '.'.

Have been looking at it a while, but not sure how to fix.

Please advise.
Thank you.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search