The SQL Server Query Store is an incredibly useful feature for monitoring and troubleshooting query performance issues. One of the handiest aspects of the Query Store is the ability to easily retrieve execution plans and query text for queries that have run in your database.
We can search for a specific query text within the Query Store using a query like this:
/*https://www.dbascrolls.com*/ SELECT qsq.query_id, qsq.last_execution_time, qsqt.query_sql_text FROM sys.query_store_query qsq INNER JOIN sys.query_store_query_text qsqt ON qsq.query_text_id = qsqt.query_text_id WHERE qsqt.query_sql_text LIKE '%your query text%';
The Query Store gives tremendous visibility into what queries have executed and how well they have performed over time. It's an invaluable tool for SQL Server performance tuning and troubleshooting.
Disclaimer: This SQL query code was originally shared on Stack Overflow. I have tested and confirmed it works as intended and wanted to reshare it here to help others.