AndyJarrett Code. Develop. Manage.

Transaction (Process ID) was deadlocked on lock

Hit this error on MSSQL and needed to find out which user was running a long query which, after a Google search, it's apparently easy to do via EXEC sp_who

This returns a lot of info about all processes so I wanted a way to query the resultset and find users on a certain database and see what commands they were running. For this I created the following

From there it was a case of killing the SPID associated with bad CMD.