SELECT TOP 1000 qs.last_execution_time, DB_NAME(st.dbid) AS database_name, OBJECT_NAME(st.objectid, st.dbid) AS object_name, 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 executed_sql FROM sys.dm_exec_query_stats AS qs CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st ORDER BY qs.last_execution_time DESC;
标签:qs,text,sql,server,查询,statement,offset,st From: https://www.cnblogs.com/hanjun0612/p/17582954.html