SQL SERVER's fuzzy query like

Source: Internet
Author: User

Write a dynamic script today, you need to have the database contains "user_" The table deleted, suddenly can't remember how to search for wildcard characters, quickly check MSDN, sorting out the fuzzy query knowledge points, save for later access.

like wildcard characters for fuzzy queries

Wildcard characters

Description

Example

%

An arbitrary string containing 0 or more characters.

The where title like '%computer% ' will find all titles that contain the word "computer" anywhere in the title.

_ (Underline)

Any single character.

WHERE au_fname like ' _ean ' will look for all 4-letter names ending in EAN (Dean, Sean, etc.)

[ ]

Any single character in the specified range ([a-f]) or collection ([abcdef]).

WHERE au_lname like ' [C-p]arsen ' will find the last name of the author that ends with Arsen and starts with any single character between C and P, such as Carsen, Larsen, Karsen, and so on. In a range search, the range contains characters that may vary depending on the collation of the collation.

[^]

Any single character that does not belong to the specified range ([a-f]) or collection ([abcdef]).

WHERE au_lname like ' de[^l]% ' will look for the last names of all authors that begin with de and whose letters are not followed by L.

Search wildcard characters

In the fuzzy query, we need to query the characters including wildcard%, _, such as I need to query table name contains "user_" table, we can use the following two ways.

SELECT * from sysobjects WHERE xtype = ' U ' and name like '%user/_% ' ESCAPE '/'
SELECT * from sysobjects WHERE xtype = ' U ' and name like '%user[_]% '

Use wildcard characters as literals

symbols /p>

like ' 5[%] '

5%

like ' [_]n '

_n

like ' [a-cdf] '

a, B, C, d  or  f

like ' [-acdf] '

-, A, C, d  or  f

like ' [[] '

[

Xiaoxiang Hidden Source: http://www.cnblogs.com/kerrycode/

SQL SERVER's fuzzy query like

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.