Do you want to compile the query without executing it? If yes, you can use SET NOEXEC ON at the beginning of the T-SQL statement.
In SQL Server, there are two ways to compile a query. The first is to compile a query by executing it, and the second is to compile a query without executing it. This blog shows you how to compile a query without executing it.
The default setting is SET NOEXEC OFF, which returns the query result once we run it.
Let's execute the below code that uses default configuration - SET NOEXEC OFF
--DEFAULT SET NOEXEC OFF SELECT COUNT(*) AS CountofSales FROM SalesLT.SalesOrderHeader
As shown below, with the statement SET NOEXEC ON, we do not get query output. SQL Server compiles the query for any syntax or object names without executing it.
SET NOEXEC ON SELECT COUNT(*) AS CountofSales FROM SalesLT.SalesOrderHeader