SQL fuzzy search usage

Source: Internet
Author: User

 

The syntax format of the like statement is:
Select * from table name where field name like corresponding value (substring)

It is used to retrieve corresponding substrings in a struct field column.

Assume that there is a database with a table Table1, and Table1 has two fields: name and sex.

Balanced data. Now we want to query records starting with "Zhang" in the name field. The statement is as follows:

Select * From Table1 where name like "sheet *"

To query records ending with "sheets", the statement is as follows:

Select * From Table1 where name like "* Sheets"

The wildcard "*" is used here. It can be said that the like statement is inseparable from the wildcard. Next we will introduce in detail

Wildcard character.
* C * c Represents CC, CBC, CBC, cabdfec, and so on. It is equivalent to the wildcard in the doscommand and represents multiple characters.

  
% C % indicates that this method, such as agdcagd, is used in many programs, mainly to query the sub-string.
  
  
A A represents a *
  
B? B Represents BRB, BFB, and so on? Wildcard, representing a single character
  
# K indicates k1k, k8k, k0k, etc.

[A-Z] represents any of the 26 letters from A to Z
  
Exclude [! Character] [! A-Z] indicates 9, 0, %, *, etc.
  
Number exclusion [! Number] [! 0-9] indicates a, B, c, d, etc.
 
Combination Type
Character [range type] character CC [! A-d] # indicates CCF # and can be combined with other methods

// Fuzzy search includes image 2011-01 **

(Ccombobox *) getdlgitem (idc_combo_year)-> getwindowtext (year );
(Ccombobox *) getdlgitem (idc_combo_month)-> getwindowtext (month );
Connect = year + "-" + month;
SQL. Format ("select * From tb_outrecords where startdate like '% S %' and

Basiccode = '% S' ", connect, leavebasiccode );

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.