Detailed description and implementation code of SqlServer English word full match, sqlserver full match

Source: Internet
Author: User

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!

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.