Returns the start index of a the first occurrence of string expression inside another string expression.
Parameters list:
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