The difference between CHARINDEX and PATINDEX for full-text retrieval in sql

The string lookup feature has been used a lot lately.

Including

1, full match search string
2, fuzzy search string

CHARINDEX and PATINDEX functions return the starting position of the specified pattern. Wildcards can be used with PATINDEX, but not with CHARINDEX.
  Both functions take 2 parameters:
  1 The mode whose position you want to get. With PATINDEX, the pattern is a literal string that can contain wildcard characters. With CHARINDEX, the pattern is a literal string (cannot contain wildcards).
  2 A string-valued expression (usually a column name).
  

select * from Power_user where U_AreaCode = '130000' and patindex('%管%',Cn)>0      

select * from Power_user where U_AreaCode = '130000' and CHARINDEX ('Tube',Cn)>0 //Cannot add universal characters, the default is fuzzy query, the found record'tube' word is in the first place;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324683422&siteId=291194637