Including records based on the likeness of two values
This section describe how to include records in the results recordset based on the likeness of a search parameter's value with a record column's value.
Using likeness instead of equality give users more flexibility when specifying the value of search parameters. For example, search words no longer need to be case sensitive. If the user enters "ohio" and the table column contains the value "Ohio", then the match is made.
Also, likeness allows you to use wildcard characters that let users perform alphabetical and partial-word searches. For example, if the user enters "m" and the table column contains the values "Morgan", "Macy", and "Michelson", then you can use a wildcard character in the SQL statement so that all three matches are made.
Suppose you decide to let users search the database by last names. The following logic is required to build the results recordset:
|
Check a record in the database table. |
|
If the value in the "last name" column of the record contains a value like the value 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 LIKE ParameterValue
ParameterValue is a SQL variable containing a search parameter. For more information, see Placing the search parameters in SQL variables.
In the SQL box in Recordset dialog box, enter the WHERE clause defining your search condition. If the variable is a text value, enclose the variable name in single quotes.
Here's how this type of search condition can be expressed in the Recordset dialog box:
If you want to give users the ability to perform partial-word searches, combine the variable with a wildcard character. The SQL wildcard character to use in this case is the percentage sign (%). Here's an example of its use:
...WHERE LASTNAME LIKE 'varLastName%'
For example, if the user types "s" as the search parameter, all records with last names starting with the letter "s" are included in the recordset, as in the following example:
If the user specifies "sm" as the search parameter, then only those records with last names that start with the letters "sm" are included:
To test the search condition without exiting the Recordset dialog box, enter a possible search word or partial word for the variable 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 value of the variable. The default value simulates a search parameter entered by a user.
Absent other search conditions in the SQL statement, setting the Default Value to a wildcard character like % means that if the user fails to enter a search parameter, then all the records in the table will be included in the recordset. If you use list boxes in your search forms, set the default option to "All" to improve usability.
Leave the Recordset dialog box open for now. You'll use it in the next section to define another kind of search condition, one based on a range of values.
|