We know that SELECT statements are used when writing queries using SQL statements. Its basic structure is as follows:
SELECT ... From ... WHERE ... Order by .....
When we use the WHERE Condition clause we know that we can make a fuzzy query from the LIKE keyword, and we know that we can do this using a wildcard character. We usually know the wildcard characters are underlined _ and percent percent. In fact, we have other query matching available, but we do not often use and ignore them. What we are ignoring is matching a specific range [] and matching a specific range of [^] two.
Let's take a look at the wildcard characters 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 particular range (for example, [a-f]) or in a specific set (for example, [abcdef]).
[^] matches any single character that is outside a specific range (for example, [^a-f]) or a particular set (for example, [^abcdef]).
Here's a list of examples to illustrate the use of these wildcard characters.
•
WHERE FirstName like ' _im ' can find all three-letter, im-terminated names (for example, Jim, Tim).
•
WHERE LastName like '%stein ' can find all employees whose last name ends with Stein.
•
where LastName like '%stein% ' can find all employees in the last name anywhere including Stein.
•
WHERE FirstName like ' [Jt]im ' can find three-letter names that end with IM and start with J or T (that is, Jim and Tim only)
•
WHERE LastName like ' m[^c]% ' can find all last names starting with M, and the following (second) letter is not C.