CHARINDEX Function - SQL


Overview


The CHARINDEX function in SQL returns the starting position of a specified substring within a string. It is useful for locating the position of a substring in a string.

Example:

SELECT CHARINDEX('world', 'hello world', 1)

Syntax:

SELECT CHARINDEX(substring_expression, string_expression, start_location)

substring_expression is the substring you want to find within the string.

string_expression is the string to be searched.

start_location is optional and specifies the position to start the search (default is 1).