Detailed description and implementation code of SqlServer English word full match, sqlserver full match
SqlServer English word full match
Environment: Vs2013 + SQL Server2012
Problem: the current database records are as follows:
The Sentence column stores English sentences. Now I want to find all sentences containing "I" (words). If I use Sentence like '% I' as a condition, the selected word "it" (Case Insensitive) will also be selected, I just want to find records of Sentences containing the word "I.
Solution: SqlServer provides pattern matching, similar to regular expressions. For more information, see relevant documents.
I first wrote a condition like this:
Sentence like '% [^ a-zA-Z] I [^ a-zA-Z] %'
The first one in the discovery, that is, "I wocould... ", the word starting with" I "is not selected. That is to say, this condition matches a non-letter symbol (no character is not allowed ), in the same way, a non-letter symbol is also needed at the end (it is not possible to have no characters), so it can be changed:
Sentence like '% [^ a-zA-Z] I [^ a-zA-Z] %' or Sentence like 'I [^ a-zA-Z] %' or Sentence like '% [^ a-zA-Z] I'
However, this is quite troublesome. If we add a non-letter number before and after Sentence, like the original "I wowould like I ", change it to "I wowould like I" (each with a space), so that it can match the condition that was first written:
''+ Sentence + ''' like '% [^ a-zA-Z] I [^ a-zA-Z] %'
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!