Examples of the CONTAINS operator
- Last Updated: January 17, 2024
- 1 minute read
- OpenEdge
- Version 12.8
- Documentation
Examples of the CONTAINS operator
Now that you know the syntax of the CONTAINS operator,
you can write queries that use it.
The following query, which displays all Item records whose CatDescription field
contains the word "hockey," demonstrates the CONTAINS operator
in its simplest form:
|
The following is the equivalent query in SQL, which also allows CONTAINS:
|
A CONTAINS string can contain multiple words connected
by the AND operator (AND or &)
and the OR operator (OR, |, or
^), optionally grouped by parentheses. For example:
|
AND operator takes precedence
over the OR operator. To override this default,
use parentheses. Using parentheses can also make the text of a query
clearer.A CONTAINS string containing multiple contiguous words,
such as:
|
Is equivalent to a CONTAINS string containing multiple
words connected by AND, such as:
|
If a CONTAINS string contains multiple words,
the order of the words is not significant. To retrieve records in
a specific order, use the CONTAINS operator with
the MATCHES operator. The following WHERE clause
retrieves records whose comments field contains the words "credit"
and "hold" in that order, perhaps with other words in between:
|
Word indexes are case insensitive unless a field participating
in the word index is case sensitive. The following two WHERE clauses are
equivalent:
|
|
You can combine CONTAINS with other search criteria,
as in the following WHERE clause, which searches for
records whose city field is Boston and whose comments field contains
the word "credit" and either the word "hold" or "watch":
|
The following example demonstrates the use of a variable with
the CONTAINS operator within the WHERE clause:
|