sp_get_query_template
spgetquerytemplate returns the parameterized form of a query.
What changes
- Input
- Not stated in the Microsoft summary.
- Output or change
- Not stated in the Microsoft summary.
Syntax at a glance
sp_get_query_template
[ @querytext = ] N'querytext'
, @templatetext OUTPUT
, @parameters OUTPUT
[ ; ]
Work example
spgetquerytemplate returns the parameterized form of a query.
Write a proposed call on paper. Name the target, required permission, expected change, and recovery step before any lab use.
Check your work Returns a parameterized query template and its parameter declarations. The input query is analyzed and is not executed.
Practice SQL
Open in SQL FlowOpen the SQL for a walkthrough. Run the example in SQL Server to check its result.
DECLARE @template nvarchar(max), @parameters nvarchar(max); EXEC sys.sp_get_query_template @querytext = N'SELECT ProductId FROM (VALUES (101), (202)) AS Products(ProductId) WHERE ProductId = 101', @templatetext = @template OUTPUT, @parameters = @parameters OUTPUT; SELECT @template AS query_template, @parameters AS parameter_declarations;
Open Microsoft Learn for full syntax, permissions, and details for your version.