{"id":199,"date":"2012-05-11T12:48:59","date_gmt":"2012-05-11T12:48:59","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2012\/05\/11\/tsql-script-to-fetch-the-code-that-is-executed-by-an-spid\/"},"modified":"2012-05-11T12:48:59","modified_gmt":"2012-05-11T12:48:59","slug":"tsql-script-to-fetch-the-code-that-is-executed-by-an-spid","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2012\/05\/11\/tsql-script-to-fetch-the-code-that-is-executed-by-an-spid\/","title":{"rendered":"TSQL Script to fetch the code that is executed by an SPID"},"content":{"rendered":"

Below is the TSQL Script to fetch the code that is executed by an SPID<\/p>\n

[sql]
\nDECLARE @sql_handle AS VARBINARY (1000)<\/p>\n

SELECT @sql_handle = SQL_HANDLE
\nFROM sys.sysprocesses WITH (NOLOCK)
\nWHERE spid = 56; –To Do: Update with SPID OF the Process<\/p>\n

SELECT *
\nFROM sys.dm_exec_sql_text (@sql_handle)
\n[\/sql]<\/p>\n","protected":false},"excerpt":{"rendered":"

Below is the TSQL Script to fetch the code that is executed by an SPID [sql] DECLARE @sql_handle AS VARBINARY (1000) SELECT @sql_handle = SQL_HANDLE FROM sys.sysprocesses WITH (NOLOCK) WHERE spid = 56; –To Do: Update with SPID OF the Process SELECT * FROM sys.dm_exec_sql_text (@sql_handle) [\/sql]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1789],"tags":[],"_links":{"self":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/199"}],"collection":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/comments?post=199"}],"version-history":[{"count":0,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/posts\/199\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/media?parent=199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/categories?post=199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlserverlearner.com\/wp-json\/wp\/v2\/tags?post=199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}