FIND( ) function

Returns a logical value indicating whether the specified string is present in a particular field, or anywhere in an entire record.

Note

The FIND( ) function and the FIND command are two separate Analytics features with significant differences.

Syntax

FIND(string <,field_to_search_in>)

Parameters

Name Type Description
string

character

The character string to search for. This search is not case-sensitive.
field_to_search_in

optional

character

The field, or variable, to search in. If omitted, the entire record is searched, including any undefined portion of the record.

Output

Logical. Returns T (true) if the specified string value is found, and F (false) otherwise.

Examples

Basic examples

Searching an entire record

Returns T for all records that contain the string "New York" in any field, across any field boundaries, and in any undefined portion of the record. Returns F otherwise:

FIND("New York")

Searching a single field

Returns T for all records that contain the string "New York" in the City field. Returns F otherwise.

FIND("New York", City)

Returns T for all records that contain the string "Ne" in the City field. Returns F otherwise:

FIND("Ne", City)

Returns T for all records that contain the string "New York" preceded by one or more spaces in the City field. Returns F otherwise:

FIND(" New York", City)

Returns T for all records that have a value in the Description field that matches, or contains, the value in the v_search_term variable. Returns F otherwise:

FIND(v_search_term, Description)

Searching multiple fields

Returns T for all records that contain the string "New York" in either the City or the City_2 fields. Returns F otherwise:

FIND("New York", City+City_2)

Returns T for all records that contain the string "New York" in either the City or the City_2 fields. Returns F otherwise:

FIND("New York", City) OR FIND("New York", City_2)

Combining with other functions

Returns T for all records that have a value in the Last_Name_2 field that matches, or contains, the trimmed value from the Last_Name field. Returns F otherwise:

FIND(ALLTRIM(Last_Name), Last_Name_2)

Remarks

When to use FIND( )

Use the FIND( ) function to test for the presence of the specified string in a field, two or more fields, or an entire record.

How matching works

The string value can be exactly matched or it can be contained within a longer string. Leading spaces in fields do not affect the search unless you include one or more leading spaces in the string value.

Search an entire record

If the optional field_to_search_in is not specified, the entire record is searched, including any undefined portion of the record. Field boundaries are ignored when the entire record is searched, and trailing spaces in fields are treated as characters.

Note

When you search an entire record, the physical record is searched. Any computed fields or related fields are not searched.

Search a subset of fields

You can concatenate two or more fields in the field_to_search_in if you want to search in a subset of the fields in a table. For example, to search both the City and City_2 fields for the string "New York":

FIND("New York", City+City_2)

The concatenated fields are treated like a single field that includes leading and trailing spaces from the individual fields, unless you use the ALLTRIM( ) function to remove spaces.

You can also build an expression that searches each field individually:

FIND("New York", City) OR FIND("New York", City_2)

If string includes a leading space, search results from the two approaches can differ.

Case sensitivity and Exact Character Comparisons

The FIND( ) function is not case-sensitive, and finds both ASCII and EBCDIC characters. The function is not affected by the Exact Character Comparisons option (SET EXACT ON/OFF).

Search in a computed field

To search in a computed field you must specify the name of the field in field_to_search_in. For example, if Vendor_City is a computed field that isolates the city in an address:

FIND("New York", Vendor_City)

Search in a related field

To search in a related field you must specify the fully qualified name of the field (that is, table.field name) in the field_to_search_in value:

FIND("New York", Vendor.Vendor_City)

Search datetime or numeric data

It is possible to use the FIND( ) function to search datetime or numeric data at the record level. Specifying the field_to_search_in is not supported for datetime or numeric searching.

The numeric or datetime string must be enclosed in quotation marks, and needs to exactly match the source data formatting rather than the formatting in the view.

Using the FIND( ) function to search datetime or numeric data in computed or related fields is not supported.

Note

Using the FIND( ) function to search datetime or numeric data is not recommended because it can be difficult to do successfully.

ACL Scripting Guide 14.1