CHARINDEX
functionsupportedCore SQL functionsSearches for the first occurrence of the first argument in the second argument and, if successful, returns the position (1-based) of the first argument in the second argument. Aliases: POSITION Note that the CHARINDEX function does not support one of the syntax variations that POSITION supports.
Syntax
supportedpartialnot supportednot scored
CHARINDEX( <expr1>, <expr2> [ , <start_pos> ] )
Parameters
| Name | Required | Description |
|---|---|---|
expr1 | required | A string or binary expression representing the value to look for. |
expr2 | required | A string or binary expression representing the value to search. |
start_pos | optional | A number indicating the position from where to start the search (with 1 representing the start of expr2). Default: 1 |
Usage notes
- If any arguments are NULL, the function returns NULL.
- If the string or binary value is not found, the function returns 0.
- If the specified optional start_pos is beyond the end of the second argument (the string to search), the function returns 0.
- If the first argument is empty (e.g. an empty string), the function returns 1.
- The data types of the first two arguments should be the same; either both should be strings or both should be binary values.
Collation details
This function does not support the following collation specifications: - pi (punctuation-insensitive). - cs-ai (case-sensitive, accent-insensitive).