Contains the user name, the database in which the SQL statement was executed, the execution start time, the driver, the host name
SELECT [Spid] = session_id, ecid, [Database] = db_name (sp.dbid),
[User] = Nt_username, [Status] = Er.status,
[Wait] = Wait_type, [individual Query] = SUBSTRING (Qt.text, ER.STATEMENT_START_OFFSET/2, case when Er.statement_end_off Set =-1 Then LEN (CONVERT (NVARCHAR (MAX), Qt.text)) * 2 ELSE Er.statement_end_offset End-er.statem Ent_start_offset)/2),
[Parent Query] = Qt.text,
program = Program_name, Hostname,
Nt_domain, Start_time
From sys.dm_exec_requests er INNER JOIN sys.sysprocesses sp on er.session_id = sp.spid Cross APPLY sys.dm_ex Ec_sql_text (Er.sql_handle) as QT WHERE session_id >/* Ignore system spids.*/and session_id not in (@ @SPID)
[Go] Querying the details of SQL statements being executed by SQL Server