Mega Code Archive

 
Categories / MSSQL Tutorial / String Functions
 

CHARINDEX returns the starting point of the first occurrence of one string within another string

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 = "rntsoft.com" 11> SET @STRING_TO_SEARCH_WITHIN = "rntsoft,rntsoft.com, www.rntsoft.com" 12> SELECT CHARINDEX(@STRING_TO_SEARCH_FOR, @STRING_TO_SEARCH_WITHIN, 6) 13> GO -----------           8 (1 rows affected)