@STRNCMP

Use the @STRNCMP function to compare two strings based on a specific number of bytes. The string can be either the name of a string (character) column or a literal string that is enclosed within single quote marks. The comparison starts at the first byte in the string.

@STRNCMP returns the following:

This function does not support NCHAR or NVARCHAR data types.

Syntax

@STRNCMP (<string1>, <string2>, <max_length>)

<string1>

The first string to be compared.

<string2>

The second string to be compared.

<max_length>

The maximum number of bytes in the string to compare.

Example

The following example compares the first two bytes of each string, as specified by a <max_length> of 2, and it returns 0 because both sets are the same.

@STRNCMP ('JOHNSON', 'JONES', 2)