Technical Article

Idle Spid Time

,

This script will search all logged in users and return the spid along with the number of seconds since that spids last batch was executed.

create table #sp_who2
( spid int
, Status varchar( 50)
, login varchar( 80)
, hostname varchar( 80)
, blkby varchar( 10)
, dbanme varchar( 80)
, command varchar( 500)
, cputime int
, diskio int
, lastbatch varchar( 22)
, programname varchar( 200)
, spid2 int
)
insert #sp_who2
exec sp_who2
select
spid
, datediff( ss, cast( 
substring( lastbatch, 1, 5) +
'/' + 
cast( datepart( year, getdate()) as char( 4)) +
' ' +
substring( lastbatch, 7, 20) as datetime)
, getdate() ) 'seconds'
 from #sp_who2
drop table #sp_who2

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating