Share via


How to: Create Queries with Named Parameters

You can specify names for the parameters in your query to help you distinguish multiple parameters. For example, if you create a parameter query that prompts for an author's name, you can use the parameter names "first name" and "last name." When you run the query in the Query and View Designer, you are prompted for the parameter by name.

To mark the parameter name as a name and not a string of literal characters, you specify parameter marker characters and then place those characters around the parameter name. For details, see How to: Specify Parameter Marker Characters.

If you use both prefix-marker and suffix-marker characters, you can name your parameters using any combination of characters, including text, numbers, punctuation, and spaces. (However, do not use null or a question mark.) If you specify only a prefix-marker character, the parameter name cannot contain spaces.

Note

The parameter name you specify is used as a variable in the environment from which you run the query. Be sure that the parameter names you use are acceptable in all environments in which you intend to use the query.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To specify a named parameter

  1. If you have not done so already, specify the parameter marker characters. For details, see How to: Specify Parameter Marker Characters.

  2. Add the columns or expressions that you want to search to the Criteria pane. If you are creating a Select query and do not want the search columns or expressions to appear in the query output, remove them as output columns.

  3. Locate the row containing the data column or expression to search, and then in the Filter grid column, enter the name of the parameter. Be sure to mark the parameter using the appropriate characters.

    By default, the Query and View Designer adds the "=" operator. However, you can edit the cell to substitute ">", "<", or any other SQL comparison operator.

See Also

Other Resources

Querying with Parameters

Specifying Search Criteria