Filtering rows

You can use WHERE and HAVING clauses and retrieval arguments in the SQL SELECT statement for the DataWindow object to limit the data that is retrieved from the database. This reduces retrieval time and space requirements at runtime.

However, you may want to further limit the data that displays in the DataWindow object. For example, you might want to:

Using filters

In the DataWindow editor, you can define filters to limit the rows that display at runtime. Filters can use most DataWindow expression functions or user-defined functions.

NoteFilters do not affect which rows are retrieved A filter operates against the retrieved data. It does not re-execute the SELECT statement.

Defining a filter

StepsTo define a filter:

  1. In the DataWindow editor, select Rows>Filter from the menu bar.

    The Specify Filter dialog box displays:

    The picture shows the Specify Filter dialog box. Across the top is a scrollable input region. At bottom left are buttons you can click to insert operators in your filter and lists of functions and columns you can paste into the filter.
  2. In the Specify Filter dialog box, enter a boolean expression that Sybase WorkSpace will test against each retrieved row.

    If the expression evaluates to TRUE, the row is displayed. You can specify any valid expression in a filter. You can paste commonly used functions, names of columns, computed fields, retrieval arguments, and operators into the filter.

    NoteInternational considerations For applications to run the same in any country, filter expressions require U.S. notation for numbers. That is, a comma always represents the thousands delimiter and a period always represents the decimal place when you specify expressions in the development environment.

  3. (Optional) Click Verify to make sure the expression is valid.

  4. Click OK.

    Only rows meeting the filter criteria are displayed in the Preview view.

    NoteFiltered rows and updates Modifications of filtered rows are applied to the database when you issue an update request.

Removing a filter

StepsTo remove a filter:

  1. Select Rows>Filter from the menu bar.

  2. Delete the filter expression from the Specify Filter dialog box, then click OK.

Examples of filters

Assume that a DataWindow object retrieves employee rows and three of the columns are Salary, Status, and Emp_Lname. Table 7-1 shows some examples of filters you might use.

Table 7-1: Sample filters

To display these rows

Use this filter

Employees with salaries over $50,000

Salary > 50000

Active employees

Status = 'A'

Active employees with salaries over $50,000

Salary > 50000 AND Status = 'A'

Employees whose last names begin with H

left(Emp_Lname, 1) = 'H'

Dynamically setting filters

You can use the setFilter and filter methods in your Java code to dynamically modify a filter that was set in the DataWindow editor.