Created
February 25, 2025 18:32
-
-
Save petesql/f159eb820f9cca943b1e91ff0a66c711 to your computer and use it in GitHub Desktop.
Logging sp_who2 Results to Table
This file contains hidden or 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
-- logging sp_who2 results to table | |
CREATE TABLE #sp_who2 ( | |
SPID INT, | |
Status VARCHAR(MAX), | |
Login VARCHAR(MAX), | |
HostName VARCHAR(MAX), | |
BlkBy VARCHAR(MAX), | |
DBName VARCHAR(MAX), | |
Command VARCHAR(MAX), | |
CPUTime INT, | |
DiskIO INT, | |
LastBatch VARCHAR(MAX), | |
ProgramName VARCHAR(MAX), | |
SPID1 INT, | |
REQUESTID INT | |
); | |
INSERT INTO #sp_who2 | |
EXEC sp_who2; | |
-- Query results (filter optional) | |
SELECT * | |
FROM #sp_who2 | |
-- WHERE DBName <> 'master' -- Exclude 'master' DB | |
ORDER BY SPID ASC; | |
-- Drop temp table | |
DROP TABLE #sp_who2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Log and Query sp_who2 Results in SQL Server
https://peter-whyte.com/2025/02/log-and-query-sp_who2-results-in-sql-server/