Searches a table for the first record with a field matching the specified expression.
LOOKUP(ReturnField, eSearchExpression, SearchedField [, cTagName]) |
Parameters
- ReturnField
- Specifies the field whose contents LOOKUP(В ) returns when the search is successful. If the search is unsuccessful, LOOKUP(В ) returns an empty character string of the same length and data type as ReturnField.
- eSearchExpression
- Specifies the search expression. The search expression is usually the contents of a field in the table, or it can correspond to the index expression of the active index or compound index tag.
- SearchedField
- Specifies the field to search. If the table does not have an active index, LOOKUP(В ) performs a sequential search through the field specified with SearchedField. If an index file or index tag is open whose index key expression is the search field you specify, LOOKUP(В ) uses the index file or index tag to perform a faster search.
- cTagName
- Specifies the name of a compound index tag for LOOKUP(В ) to use in the search. A compound index search is the fastest search LOOKUP(В ) can perform.
Return Value
Character, Numeric, Currency, Float, Integer, Double, Date, DateTime, or Logical
Remarks
If the search is successful, LOOKUP(В ) moves the record pointer to the matching record and returns the contents of a specified field in the record.
If the search expression is not found, LOOKUP(В ) returns a blank character string the same length and data type as ReturnField. The record pointer is positioned at the end of the file.
If LOOKUP(В ) is used to search a parent table, record pointers in all related child tables are moved to the related records.
This function cannot be optimized with Rushmore Query Optimization.
Example
In the following example, LOOKUP(В ) uses the index tag company
to search for the first occurrence of the string "Ernst Handel." If the search is successful, LOOKUP(В ) returns the contents of the contact
field and @В ...В SAY displays the return value.
В | Copy Code |
---|---|
CLOSE DATABASES OPEN DATABASE (HOME(2) + 'data\testdata') USE customer ORDER company && Open Customer table CLEAR @ 2,2 SAY LOOKUP(contact, 'Ernst Handel', company, 'company') |