SQL Server – querying active users by database

use master go declare @table table(         spid int,         status varchar(max),         login varchar(max),         hostname varchar(max),         blkby varchar(max),         dbname varchar(max),         command varchar(max),         cputime int,         diskio int,         lastbatch varchar(max),         programname varchar(max),        …