SQL Server English word full word matching detailed and implementation code _MSSQL

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.