Finding the Start Position of a String Within Another String : CHARINDEX « String Functions « SQL Server / T-SQL Tutorial






4>
5> SELECT CHARINDEX('String to Find', 'This is the bigger string to find something in.')
6> GO

-----------
         20

(1 rows affected)
1>








12.3.CHARINDEX
12.3.1.CHARINDEX returns the starting point of the first occurrence of one string within another string.
12.3.2.Get index of the delimiting space
12.3.3.SELECT CHARINDEX('Mars', 'The stars near Mars are far from ours')
12.3.4.select CHARINDEX('SQL', ' SQL Server')
12.3.5.select CHARINDEX('-', '(559) 555-1212')
12.3.6.Finding the Start Position of a String Within Another String