SELECT IndividualQuery= SUBSTRING (qr.text,qs.statement_start_offset/2,
(CASE WHEN qs.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qr.text)) * 2
ELSE qs.statement_end_offset END - qs.statement_start_offset)/2)
FROM SYS.DM_EXEC_REQUESTS qs OUTER APPLY SYS.DM_EXEC_SQL_TEXT(qs.sql_handle) AS qr
WHERE qr.text is not null and qs.session_id='255'
dbcc inputbuffer(255)
转载于:https://www.cnblogs.com/yuannfei19841121/archive/2010/09/04/1817943.html