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, 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 expression2 is NULL, returns 0.
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).
ANSI SQL – Compliance level: Transact-SQL extension.
Any user can execute charindex.
For general information about string functions, see “String functions”.
Function patindex