2 Jessica Ruvalcaba
(2 row(s) affected)
As we knew that the last name was Ruvalcaba, we only needed to place a wildcard
immediately before the last name. But what would happen if we didnt know
how to spell the entire last name? That name is pretty difficult to spell! You could
solve the problem by modifying your SQL statement to use two wildcards as
follows:
SELECT EmployeeID, Name
FROM Employees
WHERE Name LIKE '%Ruv%'
In this case, the wildcard is placed before and after the string Ruv. Although this
statement would return the same values we saw in the results table above, it
would also return any employees whose names (first or last) contain the sequence
Ruv. As SQL is case-insensitive, this would include the names Sarah Ruvin, Jonny
Noruvitch, Truvor MacDonald, and so on.
Using the IN Operator
We use the IN operator in SELECT queries primarily to specify a list of values that
we want to match in our WHERE clause. Lets say we want to find all employees
who live in California, Indiana, and Maryland. You could write the following
SQL statement to accomplish this task:
SELECT Name, State
FROM Employees
WHERE State = 'CA' OR State = 'IN' OR State = 'MD'
A better way to write this statement uses the IN operator as follows:
SELECT Name, State
FROM Employees
WHERE State IN ('CA', 'IN', 'MD')
If you execute this query, youll get the expected results. Since our database only
contains employees living in CA, only those records will be displayed.
Name State
-------------------------------- --------------------------------
Zak Ruvalcaba Ca
Jessica Ruvalcaba Ca
305
Using the IN Operator

Get Build Your Own ASP.NET 2.0 Web Site Using C# & VB, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.