select * from sysprocesses 
自己加条件处理

解决方案 »

  1.   

    Select count(distinct hostname) from master..sysprocesses
    where hostname > ''
      

  2.   

    use master
    goselect count(*) 当前连接到SQLSERVER的用户数 from dbo.sysprocesses where status<>'background'  
    exec sp_who2
      

  3.   

    use master
    goselect count(*) 当前连接到SQLSERVER的用户数 from dbo.sysprocesses where status<>'background'  
    exec sp_who2
      

  4.   

    --连接的用户名
    select hostname from master..sysprocesses where hostname<>'' group by hostname
    --连接的用户数
    select count(distinct(hostname)) from master..sysprocesses where hostname<>''
      

  5.   

    select count(distinct hostname) from master..sysprocesses where hostname > ''
      

  6.   

    可以取出连接数了,如何能够知道连接到指定数据库的连接数,比如连接到数据库aaa的用户连接数是多少?
      

  7.   

    select * from master..sysprocesses where dbid=db_id(N'yourdbname')
      

  8.   

    declare @db varchar(255)
    select @db=数据库名
    select count(distinct(hostname)) from master..sysprocesses where hostname<>'' and dbid=(select dbid from master..sysdatabases where name=@db)
      

  9.   

    select count(distinct hostname) from master..sysprocesses where hostname > ''
    and dbid=db_id('aaa')