Returns an integer representing the starting position of an expression.
charindex(expression1, expression2 [, start])
select charindex("wonderful", notes) from titles where title_id = "TC3218"
----------- 46
select name from spt_values where charindex( 'NO', name, 1000 ) > 0
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).
If only one of expression1 or expression2 is a locator, the datatype of the other expression must be implicitly convertible to the datatype of the LOB referenced by the locator.
When expression1 is a locator, the maximum length of the LOB referenced by the locator is 16KB.
The start value is interpreted as the number of characters to skip before starting the search for varchar, univarchar, text_locator, and unitext_locator datatypes, and as the number of bytes for binary and image_locator datatypes.
The maximum length of expression1 is 16,384 bytes.
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).
See also Transact-SQL Users Guide.
ANSI SQL – Compliance level: Transact-SQL extension.
Any user can execute charindex.