SELECT 
    qsq.query_id,
    qsqt.query_sql_text,
    qsp.plan_id,
    qsrsi.start_time AS interval_start_time,
    qsrsi.end_time   AS interval_end_time,
    qsr.execution_type_desc,
    qsr.count_executions,
    qsr.avg_duration / 1000.0 AS avg_duration_ms,
    qsr.avg_cpu_time / 1000.0 AS avg_cpu_time_ms,
    qsr.last_duration / 1000.0 AS last_duration_ms,
    qsr.last_execution_time
FROM sys.query_store_query qsq
INNER JOIN sys.query_store_query_text qsqt
    ON qsq.query_text_id = qsqt.query_text_id
INNER JOIN sys.query_store_plan qsp
    ON qsq.query_id = qsp.query_id
INNER JOIN sys.query_store_runtime_stats qsr
    ON qsp.plan_id = qsr.plan_id
INNER JOIN sys.query_store_runtime_stats_interval qsrsi
    ON qsr.runtime_stats_interval_id = qsrsi.runtime_stats_interval_id
WHERE 1=1
AND qsqt.query_sql_text LIKE '%@__ToString_0%'
AND [qsrsi].[start_time] BETWEEN '2025-10-08 10:55:00' AND '2025-10-08 11:05:00'
ORDER BY qsr.avg_duration / 1000.0 DESC;

RETURN

SELECT qsqt.query_sql_text,qsr.*
FROM sys.query_store_query qsq
INNER JOIN sys.query_store_query_text qsqt
    ON qsq.query_text_id = qsqt.query_text_id
INNER JOIN sys.query_store_plan qsp
    ON qsq.query_id = qsp.query_id
INNER JOIN sys.query_store_runtime_stats qsr
    ON qsp.plan_id = qsr.plan_id
INNER JOIN sys.query_store_runtime_stats_interval qsrsi
    ON qsr.runtime_stats_interval_id = qsrsi.runtime_stats_interval_id
WHERE 1=1
AND [qsq].[query_id] = 18134177
AND qsp.plan_id = 18157773
AND [qsrsi].[start_time] BETWEEN '2025-10-08 10:55:00' AND '2025-10-08 11:05:00'