SQL Query to run in SQL Server Agent to Kill all processes with wait time over 2 minutes and by host name.
I want to run the job every 10 seconds and monitor processes from a select few host names whose wait times are >2 minutes. I put together the following:
select 'kill '
+ cast(session_id as varchar(20))
+ cast(session_id as varchar(20))
from sys.dm_exec_sessions
where host_name = 'TS2012' and wait_time = '120000'
Tried the following code and it will kill the hosts but cant get the wait time to resolve.
select 'kill '
+ cast(session_id as varchar(20)) + cast(session_id as varchar(20))
from sys.dm_exec_sessions
where host_name = 'TS2012' and wait_time = '120000'
1条答案
按热度按时间sf6xfgos1#
wait time is in another view -- join to it to filter on it. Like this: