Query parameters
There can be parameters in a query text. Let us see the following query:
select * from DVDs
where Title = @param1
This is the query to MS SQL demonstration database. The parameter with param1
name is defined in a query. Here it should be noted: method of describing parameters in a query differs for different DBMS. For MS SQL a parameter is marked by a @
symbol, MS Access parameters do not have names and are marked by the ?
symbol.
If your SQL query contains parameters, you have to declare them. It can be done in the third step of the "Query Wizard" which we have looked at above. To create a parameter, press the "Add parameter" button. A new parameter will be created:
The following parameter's properties should be set in the properties window:
Property | Description |
---|---|
Name | Parameter name. Here you need to indicate the same name which you use in the query text. Some DBMS (for example, MS Access) do not support named parameters. In this case do not change this property. |
DataType | Parameter data type. |
DefaultValue | Value which will be used if the Expression property is not specified, or if it is impossible to calculate it (for example, when operating with the query in the report design mode). |
Expression | Expression which returns parameter's value. This expression will be processed when you run the report. You can indicate any expression in this property (see details in the "Expressions" chapter). |
Size | Parameter data size. This property must be specified if the parameter has a string specified in the DataType property. |
If you set the parameter properties incorrectly, you will get an error when turning to the last page of the wizard.