• Don't have time to help with the query itself, but I noticed you are using sys.sysprocesses. This is a SQL Server 2000 system table and is for backward compatibility. You should lookup in Books Online the DMV's you should used to replace this table as sys.sysprocesses has been deprecated and could disappear in a future version of SQL Server.

    The one DMV that comes to mind is sys.processes.