Filtering sp_who2

by bitznbitez

For those times when you want to filter the output of sp_who2 here is a hack to make it possible….  You change the filter to whatever you want to look at in the output.

CREATE TABLE #sp_who2_temp
(
 SPID INT, 
 Status VARCHAR(1000) NULL, 
 Login SYSNAME NULL, 
 HostName SYSNAME NULL, 
 BlkBy SYSNAME NULL, 
 DBName SYSNAME NULL, 
 Command VARCHAR(1000) NULL, 
 CPUTime INT NULL, 
 DiskIO INT NULL, 
 LastBatch VARCHAR(1000) NULL, 
 ProgramName VARCHAR(1000) NULL, 
 SPID2 INT NULL,
 RequestId int NULL
)
;
INSERT INTO #sp_who2_temp
EXEC sp_who2
;
SELECT *
FROM #sp_who2_temp
WHERE Login != 'sa'
;
DROP TABLE #sp_who2_temp
;
Advertisements