Query to get the SQL text of a particular process (SPID)

Query to get the SQL text of a particular process (SPID)

To know the process id run sp_who2. You will get the process id.

After getting the process id run the below batch to get the SQL text:

DECLARE @sqlhandle binary(20)
SELECT @sqlhandle=sql_handle FROM sysprocesses WHERE spid=90 — here I use the process id as 90
SELECT text FROM ::fn_get_sql(@sqlhandle)

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

%d bloggers like this: