Condividi tramite


LOOKUP( ) Function

Searches a table for the first record with a field matching the specified expression.

LOOKUP(ReturnField, eSearchExpression, SearchedField [, cTagName])

Return Values

Character, Numeric, Currency, Float, Integer, Double, Date, DateTime, or Logical

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 doesn't 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.

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 isn't 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 can't be optimized with Rushmore.

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.

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')

See Also

FIND | INDEX | LOCATE | SEEK | SEEK( )