Created
May 13, 2022 14:45
-
-
Save Otterpohl/93e0825ab2c2a7954f525ea810770339 to your computer and use it in GitHub Desktop.
Get sp_who2 results as a table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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