--关键字:cross apply & outer apply
--最后更新:2011-10-20 作者:Ronli--更新链接:http://www.cnblogs.com/ronli/archive/2011/10/20/execSQLog.html SELECT TOP 1000 --创建时间 QS.creation_time, --查询语句 SUBSTRING(ST.text,(QS.statement_start_offset/2)+1, ((CASE QS.statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE QS.statement_end_offset END - QS.statement_start_offset)/2) + 1 ) AS statement_text, --执行文本 ST.text, --执行计划 QS.total_worker_time, QS.last_worker_time, QS.max_worker_time, QS.min_worker_timeFROM sys.dm_exec_query_stats QS--关键字CROSS APPLY sys.dm_exec_sql_text(QS.sql_handle) STWHERE --根据时间搜索 QS.creation_time BETWEEN '2011-10-20 16:00:00' AND '2011-10-20 17:00:00' --根据语句内容搜索 AND ST.text LIKE '%%'ORDER BY QS.creation_time DESC