Do you remember the
LIKE operator from the SQL Basics in SQL Server course? If not, here's a short explanation and a very simple exercise.
LIKE operator matches string values to a pattern. If you don't know the exact pattern, you can use special signs to fill in the bits you're unsure about. For instance, a
% represents zero or more characters;
_ represents exactly one character.
Let's find out which copywriters have a last name 5 letters long that starts with an S, as well as a first name that starts with an A:
WHERE LastName LIKE N'S____'
AND FirstName LIKE N'A%';
In the first pattern, the first letter is S because the last name has to start with this letter. Next, we use 4 underscores; the last name must have exactly 5 letters in total: S plus four more. So we get
N'S____'. The second pattern matches the letter A, followed by arbitrary characters.