SQL Server English word whole word match
Environment: Vs2013+sql Server2012
Question: Now the database records are as follows:
The sentence column preserves the sentences in English, I now want to find all the sentences that contain "I" (words), if I use sentence like '%I ' as a condition, then there is the word "it" (case-insensitive) as the one selected above. It will also be select, and I just want to find a record of the sentence containing the word "I".
WORKAROUND: SQL Server provides pattern matching, similar to regular, with detailed content to consult related documents.
I first wrote one such condition:
Sentence like '%[^a-za-z]i[^a-za-z]% '
Find the first one in the picture above, which is "I would ...", the word "I" is not selected, that is to say, this condition is matched by a non-alphabetic symbol (no character is not possible), then the same reason, The last side also requires a non-letter symbol (no characters are also not possible), so can be changed to:
Sentence like '%[^a-za-z]i[^a-za-z]% ' or sentence as ' i[^a-za-z]% ' or sentence like '%[^a-za-z]i '
However, feel this is more troublesome, if the sentence before and after each plus a non-alphanumeric number, like the original "I would likes I", turn it into "I would kind I" (preceded by a space), so that you can match the first to write the condition:
' +sentence+ ' like '%[^a-za-z]i[^a-za-z]% '
Thank you for reading, I hope to help you, thank you for your support for this site!