Returns the position of the first occurrence of one string in another.
CHARINDEX ( string-expression1, string-expression2 )
string-expression1 The string you are searching for. This string is limited to 255 bytes.
string-expression2 The string to be searched.
The statement:
SELECT emp_lname, emp_fname FROM employee WHERE CHARINDEX('K', emp_lname ) = 1
returns the following values:
emp_lname |
emp_fname |
---|---|
Klobucher |
James |
Kuo |
Felicia |
Kelly |
Moira |
The position of the first character in the string being searched is 1.
If the string being searched contains more than one instance of the other string, then CHARINDEX returns the position of the first instance.
If the string being searched does not contain the other string, then CHARINDEX returns 0.