We know that the SELECT statement is used when SQL statements are used to write queries. Its basic structure is as follows:
SELECT... FROM... WHERE... order ......
When using the WHERE Condition Clause, we know that we can perform fuzzy queries using the LIKE keyword, and we also know that we can use wildcards to implement this. The wildcard characters that we usually know include underlines (_) and percent signs (%. In fact, we still have other queries available, but they are not frequently used and ignored. What we ignore is matching a specific range [] and matching a specific range [^.
The following describes the wildcards defined in Microsoft SQL Server:
Wildcard description
_ (Underline) matches any single character
% Matches a string that contains one or more characters.
[] Matches any single character in a specific range (for example, [a-f]) or a specific set (for example, [abcdef.
[^] Matches any single character other than a specific range (for example, [^ a-f]) or a specific set (for example, [^ abcdef.
The following examples describe how to use these wildcards.
•
WHERE FirstName LIKE '_ im' can find names ending with im (for example, Jim and Tim) with all three letters ).
•
WHERE LastName LIKE '% stein' can be used to locate all employees whose names end with stein.
•
WHERE LastName LIKE '% stein %' can be used to locate all employees whose surnames include stein.
•
WHERE FirstName LIKE '[JT] im' can find names with three letters ending with im and starting with J or T (I .e., only Jim and Tim)
•
WHERE LastName LIKE'm [^ c] %' can find all the surnames starting with m and ending with (second) Letters not c.