CHARINDEX returns the starting point of the first occurrence of one string within another string. : CHARINDEX « String Functions « SQL Server / T-SQL Tutorial






A value of 0 is returned if the string is not found.
CHARINDEX does not take into account whether the strings are upper or lower case.

8> DECLARE @STRING_TO_SEARCH_FOR varchar(4)
9> DECLARE @STRING_TO_SEARCH_WITHIN varchar(100)
10> SET @STRING_TO_SEARCH_FOR = "java2s.com"
11> SET @STRING_TO_SEARCH_WITHIN = "java2s,java2s.com, www.java2s.com"
12> SELECT CHARINDEX(@STRING_TO_SEARCH_FOR, @STRING_TO_SEARCH_WITHIN, 6)
13> GO

-----------
          8

(1 rows affected)








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