Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Simple text functions
How to modify Strings


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.

The 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:

FROM Copywriter
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.


Show all items names containing an N'e'.

Stuck? Here's a hint!

Use N'%e%' in the LIKE operator to select all names containing an e.