4.27 STRNCMP

Use @STRNCMP to compare two strings, up to a specified number of characters in each string. Trailing spaces are truncated before comparing the strings. The compare returns:

  • 0 if the strings are equal.

  • -1 if the first string is less than the second string.

  • 1 if the first string is greater than the second string.

Syntax

@STRNCMP (compare_data, compare_data, max_compare_length)
compare_data

The data to compare. Can be a character column or literal string.

max_compare_length

Specifies a number of characters to be compared in each string. For example, if you specify 2, the first two characters of each string are compared. If they are equal, 0 (zero) is returned.

Example

This example returns 0, since the first two characters of both strings are equal.

result = @STRNCMP ("JOHNSON", "JONES", 2)