- Build and test the T-SQL statements to retrieve the required Query Store statistics:
SELECT [rs].[avg_duration], [rs].avg_logical_io_reads, [qst].[query_text_id], [qsq].[query_id], [qst].[query_sql_text], CASE WHEN [qsq].[object_id] = 0 THEN N'Ad-hoc' ELSE OBJECT_NAME([qsq].[object_id]) END AS [ObjectName], [qsp].[plan_id], GETUTCDATE() AS CurrentUTCTime, [rs].[last_execution_time], CAST((DATEADD(MINUTE, -(DATEDIFF(MINUTE, GETDATE(), GETUTCDATE())), CAST((DATEADD(MINUTE, -(DATEDIFF(MINUTE, GETDATE(), GETUTCDATE())), [rs].[last_execution_time])) AS datetime2(0)) AS [LocalLastExecutionTime]FROM [sys].[query_store_query] [qsq] JOIN [sys].[query_store_query_text] [qst] ON [qsq].[query_text_id] = [qst].[query_text_id]JOIN [sys].[query_store_plan] ...