@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:
-
–1
if the first string is less than the second. -
0
if the strings are equal. -
1
if the first string is greater than the second.
This function does not support NCHAR
or NVARCHAR
data types.
Syntax
@STRNCMP (string1, string2, max_length)
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)