Use parameters
Last modified: August 8, 2024
What is a parameter?
A parameter is a placeholder for a variable that contains a value of some type that is passed to a database server along with the SQL text at the query execution time. Also, a parameter can hold values returned by a server after the query or stored procedure execution.
You can benefit from using parameters in the following situations:
-
When you execute a query multiple times with different input values
-
When you debug a query from your application code
Add parameters to a query
Parameters are declared using the @ prefix followed by the parameter name. A prefix is included to the name of the parameter.
For example:
SELECT
Employee.*
FROM
HumanResources.Employee
WHERE
Employee.JobTitle = @Job AND
Employee.VacationHours <= @Level
@Job and @Level are parameters in this query. If you execute the query, the Edit Parameters window appears where you can enter the required parameters, for example:
Click OK to save the changes and see the result. The query returned the record with the specified parameters:
Modify parameter values and types
When you run a query that contains parameters with empty values, you will automatically be prompted to initialize them.
To modify parameter values and types, select Edit Parameters on the toolbar or press F8. In the Edit Parameters window that opens, set parameters’ type, value, and other properties.
Note
When you execute a query with preset parameter values, you will not be automatically prompted to edit them. To edit parameters, press F8 or select Edit Parameters on the toolbar.
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by Data Compare for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.