Can anyone help me please, either by giving me the query or pointing me to an article, as I can't seem to find one.
I have the SPID of a session that raised an error and we need to know the full SQL text of the query that was run by that SPID.
Can anyone help please?
Please note that I have tried the following but none of them gives me the full SQL text:
DECLARE @sqltext VARBINARY(128)
SELECT @sqltext = sql_handle
FROM sys.sysprocesses
WHERE spid = 174
SELECT TEXT
FROM sys.dm_exec_sql_text(@sqltext)
GO
SELECT
sysprc.spid,sysprc.waittime,sysprc.lastwaittype,DB_NAME(sysprc.dbid) AS database_name,
sysprc.cpu,sysprc.physical_io,sysprc.login_time,sysprc.last_batch,sysprc.status,
sysprc.hostname,sysprc.[program_name],sysprc.cmd,sysprc.loginame,
OBJECT_NAME(sqltxt.objectid) AS [object_name],sqltxt.text
FROM sys.sysprocesses sysprc
OUTER APPLY sys.dm_exec_sql_text(sysprc.sql_handle) sqltxt
where spid = 174
DBCC INPUTBUFFER(174)
go