If you’ve ever needed to work with sp_who2 to figure out what’s going on, then you know it would be nice to be able to sort the results, right?
Well, if you use the following code, then you’ll get exactly that functionality. Enjoy!
CREATE TABLE #who2 ( spid INT , [status] SYSNAME , [sid] SYSNAME , hostname SYSNAME , blocked SYSNAME , dbname VARCHAR(50) , cmd VARCHAR(300) , cpu u , physical_io SYSNAME , lastbatch VARCHAR(50) , [dbid] SYSNAME , loginname SYSNAME , last_batch_char SYSNAME , programname SYSNAME , lastcol INT ) INSERT INTO #who2 EXEC sp_who2 SELECT * FROM #who2 WHERE blocked is not null DROP TABLE #who2