Including records based on a range of values
This section describe how to include records in the results recordset based on whether a record column's value falls within the range of two search parameter values.
Suppose you decide to let users search the database by a date range. The following logic is required to build the results recordset:
|
Check a record in the database table. |
|
If the value in the "date" column of the record falls between the two date values submitted by the user, then include that record in the results recordset. |
|
Check the next record in the table. |
You can express this logic in SQL using a WHERE clause, as follows:
WHERE ColumnName BETWEEN ParameterValue1 AND ParameterValue2
ParameterValue1 and ParameterValue2 are SQL variables containing search parameters.For more information, see Placing the search parameters in SQL variables.
In the SQL box in the Recordset dialog box, enter the WHERE clause defining your search condition. If the variables are dates and you're working with a Microsoft Access database, enclose the variable names with # signs.
Here's how this type of search condition can be expressed in the Recordset dialog box:
For example, if the user enters "7/1/99" and "12/31/99" as the range parameters, all employees starting in the second half of 1999 are included in the recordset, as in the following example:
To test the search condition without exiting the Recordset dialog box, enter possible range-start and range-end variables in the Default Value column in the Variables area, then click Test. UltraDev generates a test recordset based on the SQL statement and the default values of the range variables. The default values simulate range parameters entered by a user.
Leave the Recordset dialog box open for now. You'll use it in the next section to combine various search conditions in one SQL statement.
|