Gary G (11/9/2007)
Do you know anyway to actually capture the SQL being executed?
Hey again, Gary. Now, some events simply do not offer that much info, unfortunately. However, I was able to modify the UPDATE statement to include the only other insight into the executed SQL that I am aware of (check out the sys.dm_exec_sql_text(sql_handle) dynamic management view). Just replace the UPDATE statement you have completely with this one (differences are the SET and the 3 lines between CROSS JOIN and WHERE):
SET tt.TextData = COALESCE(info.EventInfo,'') + ' --SQL-> ' + COALESCE(sqltext.text, '')
FROM dbo.TraceTable tt
INNER JOIN inserted ins
ON ins.RowNumber = tt.RowNumber
CROSS JOIN #DBCCInfo info
INNER JOIN sys.sysprocesses sp -- this table has the SPID and sql_handle
ON sp.spid = tt.SPID -- match SPID between processes and TraceTable
CROSS APPLY sys.dm_exec_sql_text(sp.sql_handle) sqltext -- this view gets the SQL
WHERE tt.TextData IS NULL
Now, keep in mind that often enough the output from DBCC INPUTBUFFER is the same as the "text" field returned by dm_exec_sql_text(). But if it is ever different then this will certainly show it as it will always display both.
Also, keep in mind that the above modification to the original UPDATE only works in SQL Server 2005. If you want it for SQL Server 2000, then that would take a little more work to re-engineer it to use the ::fn_get_sql() function since there is no CROSS APPLY in SQL Server 2000.
I hope this helps.