Microsoft SQL Server CharIndex


Example

Returns the start index of a the first occurrence of string expression inside another string expression.

Parameters list:

  1. String to find (up to 8000 chars)
  2. String to search (any valid character data type and length, including binary)
  3. (Optional) index to start. A number of type int or big int. If omitted or less then 1, the search starts at the beginning of the string.

If the string to search is varchar(max), nvarchar(max) or varbinary(max), the CHARINDEX function will return a bigint value. Otherwise, it will return an int.

SELECT CHARINDEX('is', 'this is my string') -- returns 3
SELECT CHARINDEX('is', 'this is my string', 4) -- returns 6
SELECT CHARINDEX(' is', 'this is my string') -- returns 5