|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, June 11, 2013 7:57 AM
Points: 13,
Visits: 120
|
|
hello,
Is there a way in whihc we can combine the out of sp_who2 with sysprocesses table in sql 2000. need to find the longest running query in sql 2000 but no luck so far..
Any help is appreciated.
regards, T
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Yesterday @ 9:14 AM
Points: 13,435,
Visits: 25,277
|
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Yesterday @ 5:34 PM
Points: 11,784,
Visits: 28,041
|
|
wow SQL 2000; edit : whoops this is clearly for 2005 or above; let me look again in my snippets; i know i have something
I have this proc saved in my snippets, which purports to identify what is SQl executing, and it does seem to grab an NTUsername; see if this helps at all? you could search for "dba_WhatSQLIsExecuting" to find the origianl thread for more ideas.
CREATE PROC [dbo].[dba_WhatSQLIsExecuting] AS /*-------------------------------------------------------------------- Purpose: Shows what individual SQL statements are currently executing. ---------------------------------------------------------------------- Parameters: None. Revision History: 24/07/2008 Ian_Stirk@yahoo.com Initial version Example Usage: 1. exec YourServerName.master.dbo.dba_WhatSQLIsExecuting ---------------------------------------------------------------------*/ BEGIN -- Do not lock anything, and do not get held up by any locks. SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
-- What SQL Statements Are Currently Running? SELECT [Spid] = session_Id , ecid , [Database] = DB_NAME(sp.dbid) , [User] = nt_username , [Status] = er.status , [Wait] = wait_type , [Individual Query] = SUBSTRING (qt.text, er.statement_start_offset/2, (CASE WHEN er.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2 ELSE er.statement_end_offset END - er.statement_start_offset)/2) ,[Parent Query] = qt.text , Program = program_name , Hostname , nt_domain , start_time FROM sys.dm_exec_requests er INNER JOIN sys.sysprocesses sp ON er.session_id = sp.spid CROSS APPLY sys.dm_exec_sql_text(er.sql_handle)as qt WHERE session_Id > 50 -- Ignore system spids. AND session_Id NOT IN (@@SPID) -- Ignore this current statement. ORDER BY 1, 2 END
Lowell
--There is no spoon, and there's no default ORDER BY in sql server either. Actually, Common Sense is so rare, it should be considered a Superpower. --my son
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Yesterday @ 5:34 PM
Points: 11,784,
Visits: 28,041
|
|
ok here's one way to do it with SQL2000:
declare @sql_handle binary(20),@spid smallint; declare c1 cursor for select sql_handle,spid from master..sysprocesses where spid >50; open c1; fetch next from c1 into @sql_handle,@spid; while (@@FETCH_STATUS =0) begin select spid, login_time, last_batch, [status], loginame, a.text from ::fn_get_sql(@sql_handle) a, master..sysprocesses b where b.spid = @spid fetch next from c1 into @sql_handle,@spid end close c1 deallocate c1;
Lowell
--There is no spoon, and there's no default ORDER BY in sql server either. Actually, Common Sense is so rare, it should be considered a Superpower. --my son
|
|
|
|