COMPARE Function

Returns the result of comparing two strings.

Category: String
Returned data type: Integer

Syntax

COMPARE(string1, string2<,case-insensitive>)

Required Arguments

string1

specifies a string to be used in the comparison; this can be specified as string constant, field name, or expression.

string2

specifies a string to be used in the comparison; this can be specified as string constant, field name, or expression.

Optional Argument

case-insensitive

specifies a Boolean string that indicates whether to compare case-insensitive strings; this can be specified as string constant, field name, or expression.

TRUE specifies that the string comparison is not case sensitive.
FALSE specifies that the comparison is case sensitive.
Default FALSE

Details

The MATCH_STRING function compares two strings lexicographically and can be used to do string comparisons using wildcards.
The return value is an integer representing the result of a lexicographical comparison of the two strings:
[-1 = string1 < string 2,
0 = string1 equals string2,
1 = string1 > string2]
To check whether two strings are equal, it is more efficient to use the == operator, for example:
if string1 == string2 then match=true

Example

// hallo comes before hello when alphabetically sorted
rc = compare("hello", "hallo" ) // outputs 1
 
// Hello comes before hello when alphabetically sorted
rc = compare("Hello", "hello" ) // outputs -1
 
modifier = null
rc = compare("Hello", "hello", modifier ) // outputs -1
rc = compare("Hello", "hello", true ) // outputs 0