CHARINDEX: Checks if a character (string) is contained in another string, and returns the starting position of the specified expression in the string.
PATINDEX: Checks if a character (string) is contained in another string, returns the starting position of the first occurrence of a pattern in the specified expression, or zero if the pattern is not found in all valid text and character data types. Subscript starting from 1 (the difference is that the latter supports fuzzy matching, the former is a full match)
1.SELECT PATINDEX ('%[^0-9]% ', ' 1235x461 ') results 5
2.SELECT PATINDEX ('%[^0-9]% ', ' 12350461 ') results 0
3.SELECT PATINDEX ('%[0-9]% ', ' SUYLLG0 ') results 7
4.SELECT PATINDEX ('%[0-9]% ', ' SUYLLG01 ') results 7
5.select PATINDEX ('%ter% ', ' interesting data ') Results 3
6.select PATINDEX ('%t_ng% ', ' interesting data ') Results 8
7.SELECT CHARINDEX (' 5 ', ' 1235x461 ') result 4 No, that's 0. The first parameter is the character to be searched (string), the second is the string to be found
8.select charindex (' Test ', ' This test is Test ' COLLATE latin1_general_cs_as) result 0 case-sensitive CS
9.select charindex (' Test ', ' This test is Test ' COLLATE latin1_general_ci_as) result 6 case insensitive CI
(Self-practice and collation of other people's information, do not do business purposes, only to do learning and communication use)
Methods in SQL to determine if a string contains characters