Question

While I caught myself re-engineering the functionality of sp_who / sp_whoisactive using the sys.sysprocesses and sys.dm_exec_session views, to get an overview about running sessions and transactions on my server, I thought: "no, instead use something already that is available and tested!"

exec sp_whoisactive @get_additional_info = 1; 

returns an additional XML column that offers lots of information, one of this is the Isolation Level.

I would like to have the isolation level in the primary resultset of sp_whoisactive. Did anyone have the same requirement and already solved it? Why is it not included in the primary resultset from scratch, since it is an important information.

sp_whoisactive

Was it helpful?

Solution

Using the built-in functionality of sp_whoisactive to return the schema of the result set, you can store that information in a temp table and then use CROSS APPLY to extract out one or more xml nodes from the additional information

--Drop temp table 
IF OBJECT_ID('tempdb.dbo.sp_whois_active') IS NOT NULL  
    DROP TABLE tempdb.dbo.sp_whois_active 

--Use 'return_schema' to create a temp table to hold the results of sp_whoisactive
DECLARE @s VARCHAR(MAX)

EXEC sp_WhoIsActive @output_column_list = '[%]'
    ,@return_schema = 1
    ,@schema = @s OUTPUT
    ,@get_additional_info = 1

SET @s = REPLACE(@s, '<table_name>', 'tempdb.dbo.sp_whois_active')

EXEC (@s)

--Populate the temp table by executing sp_whoisactive
EXEC sp_WhoIsActive @output_column_list = '[%]'
    ,@destination_table = 'tempdb.dbo.sp_whois_active'
    ,@get_additional_info = 1

--Select all of the columns from the temp table and
--use CROSS APPLY to extract one or more xml nodes
SELECT who.*
    ,N.C.value('transaction_isolation_level[1]', 'varchar(100)') IsolationLevel
FROM tempdb.dbo.sp_whois_active who
CROSS APPLY additional_info.nodes('//additional_info') N(C)
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top