Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Open SSMS and connect to the desired SQL instance

  • Right-click the instance name → New Query

  • Copy and paste the code below on the right panel:

Code Block
languagesql
SELECT 
    HostName,
    Loginame,
	Login_Time,
	Program_Name,
    DB_NAME(dbid) [DB_Name],
	right(convert(varchar, 
        dateadd(ms, datediff(ms, last_batch, getdate()), '1900-01-01'), 
        121), 12) as 'Duration',
    CPU as CPU_Time,
    Status,
	Cmd,
	SpID
FROM
    master.dbo.sysprocesses
WHERE
    spid > 50
    AND status not in ('background', 'sleeping')
	-- AND Loginame LIKE '%UserName%'  -- <--- Filter by Username
ORDER BY 
    Duration DESC

...