;WITH t AS( SELECT [Spid] = session_Id, ecid, [Database] = DB_NAME(sp.dbid), [User] = nt_username, [Status] = er.status, [Wait] = wait_type, , ( THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) ), [Parent Query] = qt.text, Program = program_name, Hostname,…