This topic contains and tries to cover following subjects
- Explanation of CHARINDEX () function in SQL
- Syntax of CHARINDEX () function in SQL
- Example to CHARINDEX () function in SQL
Articles contains and tries to provide answer to following questions and issues:
- What is CHARINDEX () function..
- How to use CHARINDEX () function..
- How to find a string an occurrence within another string
- How to check if a string exists in another string
Articles may require following knowledge:
- Basic query flow in SQL
- SQL Server Management Studio
- SQL Server string functions
Explanation of CHARINDEX () function in SQL
CHARINDEX function is used to find an occurrence of a string in another string . Functions returns position number to indicate where the string starts. In essence, as function name indicates, it indicates the start position of a char acter on encounter. It locates a string in a column of a table.
If the provided source string is not encountered in target string , the function returns zero value which indicates "it is not found".
Syntax of CHARINDEX () function in SQL
Syntax for stuff function is as follows:
CHARINDEX ( source string , target string , start position (default is 1) )
Example of CHARINDEX () function in SQL
To demonstrate how to find a start position of a string in another string in SQL..
Query is as follows: