As you learned in Using a host variable, you can compose dynamic queries using host variables. VisualAge also provides a way to make an entire WHERE clause dynamic, operator and all, which enables you to restrict the result table rows of a query in even more flexible ways.
After following the steps in this section, you will have created the following query. This query must be created manually.
SELECT * FROM STAFF :whereClause
This query will select all rows from the STAFF table that meet the conditions of the variable WHERE clause.
The SQL Details window is displayed and looks like this:

SELECT * FROM STAFF :whereClause
| Note: | You must enter :whereClause as shown. The dynamic WHERE clause will not work otherwise. |
Using a query with a dynamic WHERE clause
In the Composition Editor, notice that the pop-up menu for your multi-row query part now includes the attribute whereClause, the name of the host variable you used for the dynamic WHERE clause.
Begin constructing your visual part as follows:
Your Composition Editor will look like this:

Complete your visual part as follows:
initializeWhereClause
| where |
((self subpartNamed: 'whereClauseIndex') value == 1)
ifTrue:
[ where := 'WHERE (STAFF.SALARY > (SELECT AVG(STAFF.SALARY) FROM STAFF))'].
((self subpartNamed: 'whereClauseIndex') value == 2)
ifTrue:
[ where := 'WHERE (STAFF.SALARY < (SELECT AVG(STAFF.SALARY) FROM STAFF))'].
(self subpartNamed: 'Multi-row Query1')
valueOfAttributeNamed: 'whereClause' put: where.
This script sets up values for the whereClauseIndex
variable. In the next section, you will see how to assign each value to
a radio button.
With this new visual part, you have a window that can be reused from different places in an application. By passing the value 1 to the window in the whereClauseIndex attribute, you can restrict the result table to staff entries with a higher-than-average salary. By passing the value 2, you can restrict the result table to staff entries with a lower-than-average salary.
Testing the dynamic WHERE clause
Where and how your window is opened depends on the design and needs of your
application, but for this example, create a test case by creating a new visual
part that looks like this:

For more information on view wrappers, see the VisualAge Smalltalk User's Guide.