Refining the data selection with a WHERE clause
- Last Updated: March 30, 2020
- 1 minute read
- OpenEdge
- Version 12.2
- Documentation
So far you've been selecting all the Customer records in the database. Now you'll refine that selection to show only those Customers from the state of New Hampshire. There is a State field in the Customer table that holds the two-letter state abbreviation for states in the USA.
ABL supports a WHERE clause in any statement
that retrieves data from the database, which will be familiar to
you if you have used SQL or other similar data access languages.
The WHERE keyword can be followed by any expression
that identifies a subset of the data. You'll learn a lot more about
this in later chapters, but for now a simple expression is all you
need.
To refine the data selection in your test procedure:
- Add the following
WHEREclause to the end of yourFOR EACHstatement:FOR EACH Customer WHERE Customer.State = "NH": - Press F2 to see the reduced list of Customers. The list should now use only a bit more than a page in the display window.
- Add a sort expression to the end of your
WHEREclause to sort the Customers in order by their City. ABL uses the keywordBYto indicate a sort sequence. For example:FOR EACH Customer WHERE Customer.State = "NH" BY Customer.City: - Press F2 to run the procedure again to see the effects of your change.