CHARINDEX (Transact-SQL)
Syntax: CHARINDEX (expression 1, expression 2, start position)
Parameters:
Expression 1
Expression that contains the sequence-be found. ' xmlspace= ' preserve ' > a character expression that contains the sequence to find. Expressiontofind is limited to 8000 characters. ' xmlspace= ' preserve ' > expression 1 contains a maximum of 8,000 characters.
Expression 2 The character expression to search for. You can make the variable (expression 1 look in Expression 2) start_location
Integer or bigint expression at which the search starts. ' xmlspace= ' preserve ' > represents the integer or bigint expressions where the search starts. Start_location is isn't specified, is a negative number, or was 0, the search starts at the beginning of Expressiontosearch. ' xmlspace= ' Preserve > If start_location is not specified , the parameter is negative or 0, the search starts at the beginning of the Expressiontosearch. The default starts from the first bit of expression 2 to find
Extended:
CHARINDEX performs a comparison operation based on the collation entered. To compare with a specified collation, you can use COLLATE to apply an explicit collation to the input.
Case sensitive:
The following example performs a case-sensitive string ' Test ' Search in ' Das ist ein Test '.
SELECT CHARINDEX (' TEST ', ' Das ist ein TEST '
COLLATE latin1_general_cs_as);
Result is 0
SELECT CHARINDEX (' Test ', ' Das ist ein Test '
COLLATE latin1_general_cs_as);
Result is 13
Case insensitive
The following example performs a case-insensitive string ' Test ' Search in ' Das ist ein Test '.
SELECT CHARINDEX (' TEST ', ' Das ist ein TEST '
COLLATE latin1_general_ci_as)
Results: 13
CHARINDEX (Transact-SQL)