Handy little sp_who2 script
I'm always hunting around for one of these scripts, so I'm sticking it here for ease of reference & in case its useful to anyone else..
select getdate()
go
if OBJECT_ID('tempdb..#spwho') > 0 drop table #spwho
go
create table #spwho (
SPID int not null
, Status varchar (255) not null
, Login varchar (255) not null
, HostName varchar (255) not null
, BlkBy varchar(10) not null
, DBName varchar (255) null
, Command varchar (255) not null
, CPUTime int not null
, DiskIO int not null
, LastBatch varchar (255) not null
, ProgramName varchar (255) null
, SPID2 int not null
)
go
insert #spwho
exec sp_who2
go
select *
from #spwho
where SPID > 50 and BlkBy != ' . '
order by LastBatch desc
go
if OBJECT_ID('tempdb..#spwho') > 0 drop table #spwho