Retrieve the text of the running SQL

-- SQL Server 2000
-- Retrieve the text of the running SQL

-- The system process ID. 
-- The system function sp_who lists the processes information.
DECLARE @spid smallint
SET @spid = 124

-- (1) use DBCC statement
DBCC INPUTBUFFER (@spid)


-- (2) fn_get_sql
-- SQL Server 2000 sp3 has fn_get_sql function to see what is running now.

DECLARE @Handle binary(20)

SELECT @handle=sql_handle 
     FROM master..sysprocesses 
     WHERE spid= @spid

select *
    from ::fn_get_sql(@handle)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s