In this tutorial you will learn how to use wildcards in SQL Server. SQL wildcards can be used when searching for data in a database. SQL wildcards are used with the LIKE operator, which acts as a comparison when searching the database.  We will use the ‘%’ and ‘_’ wildcards in SQL Server:

% - A substitute for zero or more characters.
_ - A substitute for exactly one character.

We will show an example of both using our Movies table.



The % Wildcard

The % wildcard searches the database for matches of zero or more characters. We will look for titles that start with ‘so’.
Code Block
Wildcard-%.sqlce
Search for titles that begin with ‘so’.
SELECT FROM Movies
WHERE Title LIKE 'so%'
Your output should be Source Code and Soul Surfer. The ‘%’ symbol after ‘so’ means that anything can follow as long as the title starts with ‘so’.


If you’re ever in the market for some great Windows web hosting, try Server Intellect. We have been very pleased with their services and most importantly, technical support.

We can also use a variation that looks for titles that contains specified letters. We will look for directors that contain the patter ‘ur’ in their name.
Code Block
Wildcard – % 2.sqlce
Find director names that contain ‘ur’.
SELECT FROM Movies
WHERE Director LIKE '%ur%'
Your output should be Limitless and The Lincoln Lawyer. Taking a page out of the previous example, we now used the ‘%’ symbol to find anything that precedes and proceeds the pattern ‘ur’.


Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.

The _ Wildcard

Like the previous wildcard, there are two forms of the _ wildcard. The first form looks for a word that begins with any character followed by a specified pattern as such:
Code Block
Wildcard-_ 1.sqlce
Look for titles that start with any character followed by ‘op’.
SELECT FROM Movies
WHERE Title LIKE '_op'
The output will be Hop. In this example, we looked for a title than begins with anything as long as the last letters are ‘op’.



The second form plays off of the first one, just more in detail. We will search for titles that begin with ‘R’, followed by any character,  followed by ‘n’, followed by any character, followed by ‘o’.
Code Block
Wildcard-_ 2.sqlce
The second form of the _ wildcard.
SELECT FROM Movies
WHERE Title LIKE 'R_n_o'
The output is Rango. This form is for helps finding commonly misspelled words easier.


We migrated our web sites to Server Intellect over one weekend and the setup was so smooth that we were up and running right away. They assisted us with everything we needed to do for all of our applications. With Server Intellect’s help, we were able to avoid any headaches!

Wildcards serve as an easier way of searching wide variety of words in a database, especially in the bigger databases.

Thanks for reading and make sure to download the source files to get a better understanding of how the code works.

Wildcards-SqlServer.zip