SQL fuzzy search statement

Source: Internet
Author: User
For more information about SQL fuzzy queries, see the following:

1. Like 'mc % 'searches all strings starting with MC (for example, mcbadden ).
2. Like '% Inger' searches all strings ending with the letter Inger (such as ringer and Stringer ).
3. Like '% en %' searches for all strings (such as Bennet, green, and mcbadden) containing the letter en at any position ).
4. Like '_ heryl' searches for names (such as Cheryl and Sheryl) of all six letters ending with heryl ).
5. Like '[Ck] ARS [EO] n' will search for the following strings: Carsen, Karsen, Carson, and karson (such as Carson ).
6. Like '[M-Z] Inger' searches for all names (such as ringer) ending with string Inger, starting with any single letter from m to Z ).
7. Like'm [^ C] %' searches for all names starting with m, and the second letter is not C (such as macfeather ).
-------------------------------------------------
A complete example is required. The following query string is previously written. The zipcode_key variable is used to query the corresponding data in zipcode of the zip code table. The query statement is used to determine that the zipcode_key variable is not a number, use % to match strings of any length, query all data items containing keywords from the address, city, and province columns in the table, and sort by province, city, and address. This example is relatively simple. As long as you understand the method, you can write more complex query statements.

SQL = "select * From zipcode where (address like '%" & zipcode_key & "%') or (city like '%" & zipcode_key & "% ') or (province like '% "& zipcode_key &" %') order by province, city, address"

Note:

"%" Can contain multiple characters,
"_" Can only represent one character,
A Chinese character is two characters. Therefore, two _ characters are used to indicate Chinese characters, that is, "_".

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.