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