Skip to content

Instantly share code, notes, and snippets.

@Otterpohl
Created May 13, 2022 14:45
Show Gist options
  • Save Otterpohl/93e0825ab2c2a7954f525ea810770339 to your computer and use it in GitHub Desktop.
Save Otterpohl/93e0825ab2c2a7954f525ea810770339 to your computer and use it in GitHub Desktop.
Get sp_who2 results as a table
DECLARE @temp_sp_who2 AS TABLE
(
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 BIGINT NULL, -- int
LastBatch VARCHAR(1000) NULL,
ProgramName VARCHAR(1000) NULL,
SPID2 INT
, RequestId INT NULL --comment out for SQL 2000 databases
)
INSERT INTO @temp_sp_who2
EXEC sp_who2
SELECT *
FROM @temp_sp_who2
WHERE SPID > 50
AND SPID <> @@SPID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment