Returns an integer representing the starting position of an expression.
charindex(expression1, expression2)
is a binary or character column name, variable or constant expression. Can be char, varchar, nchar, nvarchar, unichar or univarchar data, binary or varbinary.
Returns the position at which the character expression “wonderful” begins in the notes column of the titles table:
select charindex("wonderful", notes) from titles where title_id = "TC3218"
----------- 46
charindex, a string function, searches expression2 for the first occurrence of expression1 and returns an integer representing its starting position. If expression1 is not found, charindex returns 0.
If expression1 contains wildcard characters, charindex treats them as literals.
If char_expr or uchar_expr is NULL, returns NULL.
If a varchar expression is given as one parameter and a unichar expression as the other, the varchar expression is implicitly converted to unichar (with possible truncation).
For general information about string functions, see “String functions”.
SQL92 – Compliance level: Transact-SQL extension.
Any user can execute charindex.
Function patindex