Example and Notes
Use this SQL Server example as a starting point for development, troubleshooting, reporting, or maintenance work. Review it against your schema, data volume, permissions, and SQL Server version before using it in production.
The builtin sp_who2 function provides information about current users, sessions, and processes in an instance of the Microsoft SQL Server Database Engine. The information can be filtered to return only those processes that are not idle, that belong to a specific user, or that belong to a specific session. The code below will show you how to run the sp_who2 function.
sp_who2
Production Review
WSI can adapt this script for your database, improve error handling, tune performance, document the logic, and help deploy it safely.