Query 1-
To know which sessions are running currently, run the following command:
SELECT @@SPID
GO
get the latest run query in our input bufferDBCC INPUTBUFFER(61)--61 is the output of above query
GO
Query 2-
DECLARE @sqltext VARBINARY(128)
SELECT @sqltext = sql_handle
FROM sys.sysprocesses
WHERE spid = 61 -- get from
SELECT @@SPID
SELECT TEXT
FROM sys.dm_exec_sql_text(@sqltext)
GO
Please note that in any session there may be multiple running queries,
but the buffer only saves the last query and that is what we will be
able to retrieve.
No comments:
Post a Comment