Этот может помочь вам. Я сам не писал, но мы иногда используем это здесь, в моей организации.
SELECT Sdest.Databasename,
Sdes.Session_Id,
Sdes.Host_Name,
Sdes.Program_Name,
Sdes.Client_Interface_Name,
Sdes.Login_Name,
Sdes.Login_Time,
Sdes.Nt_Domain,
Sdes.Nt_User_Name,
Sdec.Client_Net_Address,
Sdec.Local_Net_Address,
Sdest.Objname,
Sdest.Query
FROM Sys.Dm_Exec_Sessions AS Sdes
INNER JOIN Sys.Dm_Exec_Connections AS Sdec ON Sdec.Session_Id = Sdes.Session_Id
CROSS APPLY
(
SELECT DB_NAME(Dbid) AS Databasename,
OBJECT_ID(Objectid) AS Objname,
ISNULL(
(
SELECT Text AS [Processing-instruction(definition)]
FROM Sys.Dm_Exec_Sql_Text(Sdec.Most_Recent_Sql_Handle) FOR Xml PATH(''), TYPE
), '') AS Query
FROM Sys.Dm_Exec_Sql_Text(Sdec.Most_Recent_Sql_Handle)
) AS Sdest
WHERE Sdes.Session_Id <> @@Spid
ORDER BY Sdec.Session_Id;