SELECT field FROM table WHERE a field Like condition, selectwhere
SQL provides four matching modes for conditions:
For example, SELECT * FROM [user] WHERE u_name LIKE '% 3%'
Represents any 0 or multiple characters. It can match any type and length of characters. In some cases, if it is Chinese, use two percent signs (%.
We will find all records with "3", such as "3 Zhang", "3 Zhang", "3 Zhang Mao", and "3 Tang sanzang.
In addition, if you need to find records with "three" and "cat" in u_name, use the and condition.
SELECT * FROM [user] WHERE u_name LIKE '% 3%' AND u_name LIKE '% cat %'
If you use SELECT * FROM [user] WHERE u_name LIKE '% 3% cat %', although you can search for three-legged cats, you cannot find the three-legged cats that meet the search criteria ".
Represents any single character. Matches any character. It is often used to limit the character length of an expression:
For example, SELECT * FROM [user] WHERE u_name LIKE '_ 3 _'
Only find that the u_name in "Tang sanzang" is three characters and the middle word is "three". Then, for example, SELECT * FROM [user] WHERE u_name LIKE '3 __'; find out that the name of the "three-legged cat" is three characters and the first word is "three;
Represents one of the characters listed in parentheses (similar to regular expressions ). Specifies a character, string, or range. The matching object must be one of them.
For example, SELECT * FROM [user] WHERE u_name LIKE '[Zhang Li Wang] san' will find "Zhang San", "Li San", and "Wang San" (rather than "Zhang Li Wang San ");
For example,  contains a series of characters (01234, abcde, and so on) it can be slightly written as "0-4", "a-e" SELECT * FROM [user] WHERE u_name LIKE 'Old [1-9]'
We will find "Old 1", "old 2", "old 9 ";
For example, SELECT * FROM [user] WHERE u_name LIKE '[^ Zhang Li Wang] san' will find "Zhao San" without the surname "Zhang", "Li", and "Wang ", sun San and others; SELECT * FROM [user] WHERE u_name LIKE 'Old [^ 1-4] '; will exclude "Old 1" to "old 4 ", search for "old 5", "old 6", and "„ 5". When the query content contains wildcards
Represents a single character not listed in parentheses. The value is the same as , but it requires that the matched object be any character other than the specified character.
Function sqlencode (str)
Str = replace (str, "[", "") 'must be at the beginning
Str = replace (str, "_", "[_]")
Str = replace (str, "%", "[%]")
Sqlencode = str
The string to be queried can be processed by this function before query.
For more information, see: http://wenku.baidu.com/view/d34d1410f18583d049645979.html