CHARINDEX: returns the starting point of the first occurrence of one string of characters within another string
1> -- CHARINDEX: returns the starting point of the first occurrence of one string of characters within
2> -- another string.
3>
4> -- A value of 0 is returned if the string is not found.
5>
6> -- CHARINDEX does not take into account whether the strings are upper or lower case.
7> -- In the example below you would hope that the CHARINDEX function would find the last Wrox, but it actually finds the WROX before that.
8>
9> DECLARE @STRING_TO_SEARCH_FOR varchar(4)
10> DECLARE @STRING_TO_SEARCH_WITHIN varchar(100)
11>
12> SET @STRING_TO_SEARCH_FOR = "a"
13> SET @STRING_TO_SEARCH_WITHIN = "abcdeAabcde"
14>
15> SELECT CHARINDEX(@STRING_TO_SEARCH_FOR, @STRING_TO_SEARCH_WITHIN, 16)
16>
17> GO
-----------
0
(1 rows affected)
1>
Related examples in the same category