Created
December 16, 2015 15:06
-
-
Save Kritner/0d8151ee8e40357ad393 to your computer and use it in GitHub Desktop.
SQL to create a table variable that will hold sp_who2 information so it's queryable
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
-- Create a variable table to hold the results of sp_who2 for querying purposes | |
DECLARE @who2 TABLE ( | |
SPID INT NULL, | |
Status VARCHAR(1000) NULL, | |
Login SYSNAME NULL, | |
HostName SYSNAME NULL, | |
BlkBy SYSNAME NULL, | |
DBName SYSNAME NULL, | |
Command VARCHAR(8000) NULL, | |
CPUTime INT NULL, | |
DiskIO INT NULL, | |
LastBatch VARCHAR(250) NULL, | |
ProgramName VARCHAR(250) NULL, | |
SPID2 INT NULL, -- a second SPID for some reason...? | |
REQUESTID INT NULL | |
) | |
INSERT INTO @who2 | |
EXEC sp_who2 | |
SELECT * | |
FROM @who2 w | |
WHERE 1=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment