how to get one year old query from plan cache

Solutions on MaxInterview for how to get one year old query from plan cache by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "how to get one year old query from plan cache"
Selma
10 Nov 2016
1SELECT TOP 10
2t.TEXT QueryName,
3s.execution_count AS ExecutionCount,
4s.max_elapsed_time AS MaxElapsedTime,
5ISNULL(s.total_elapsed_time / 1000 / NULLIF(s.execution_count, 0), 0) AS AvgElapsedTime,
6s.creation_time,
7ISNULL(s.execution_count / 1000 / NULLIF(DATEDIFF(s, s.creation_time, GETDATE()), 0), 0) AS FrequencyPerSec
8,query_plan
9FROM sys.dm_exec_query_stats s
10CROSS APPLY sys.dm_exec_query_plan( s.plan_handle ) u
11CROSS APPLY sys.dm_exec_sql_text( s.plan_handle ) t
12ORDER BY creation_time