Skip to content

Instantly share code, notes, and snippets.

@Kritner
Created December 16, 2015 15:06
Show Gist options
  • Save Kritner/0d8151ee8e40357ad393 to your computer and use it in GitHub Desktop.
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
-- 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