title: How to find user activities on a particular database in SQL Server 2000
body: <p>Which query shows the user activities on a partiular database in SQL Server 2000? I need to know which all users are loged in one of the databases and also need to see the queries fired by these users</p>
  
  <pre><code>FUNCTION [dbo].[Show_my_process] (@SPID INT) 
  returns VARCHAR(8000) 
  AS 
    BEGIN 
        DECLARE @sql_handle   BINARY(20), 
                @handle_found BIT 
        DECLARE @stmt_start INT, 
                @stmt_end   INT 
        DECLARE @line     NVARCHAR(4000), 
                @wait_str VARCHAR(8) 
        DECLARE @sql_process AS VARCHAR(8000) 
  
        SELECT @sql_handle = sql_handle, 
               @stmt_start = stmt_start / 2, 
               @stmt_end = CASE 
                             WHEN stmt_end = -1 THEN -1 
                             ELSE stmt_end / 2 
                           END 
        FROM   master.dbo.sysprocesses 
        WHERE  spid = @spid 
               AND ecid = 0 
  
        SELECT @sql_process = Substring(text, COALESCE(NULLIF(@stmt_start, 0), 1),
                               CASE 
                                     @stmt_end 
                              WHEN -1 
                                     THEN 
                                     Datalength(text) 
                                     ELSE ( 
                                                    @stmt_end - @stmt_start ) 
                              END) 
        FROM   ::fn_get_sql(@sql_handle) 
  
        RETURN @sql_process 
    END  
  
  SELECT dbo.SHOW_MY_PROCESS(SPID) 
  FROM MASTER.DBO.SYSPROCESSES 
  WHERE SPID &gt; 50
  </code></pre>
  
  <p>If I run this I get the queries but the problem is I can not see the queries run by other users</p>