Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Concatenation
Simple text functions
How to modify Strings
19. The LEFT() and RIGHT() functions
Summary

Instruction

Fantastic! You can now get a substring (part of a string) from a larger string. But what if you need a substring located at the beginning or end of the string? Two other functions let you do this: LEFT() and RIGHT(). As you might guess, LEFT() takes the substring starting at the leftmost (leading) character, and RIGHT() starts from the final character and works backwards. All you need to specify is the string and how many characters you want to return:

SELECT
  Right(Name, 3) AS NameEnd
FROM Item;
a14

In this case, RIGHT() returns the last 3 letters of an item's name.

Exercise

The boss of the marketing agency would like to get the first initial of every copywriter's first name and the last letter of their last name.

Select a list of the first letter of each copywriter's first name and the last letter of their last name. If the first name or last name is empty, omit that writer from the list. Name the columns BeginFirstName and EndLastName.

Stuck? Here's a hint!

Use LEFT() for FirstName and RIGHT() for LastName. Set the length parameter to 1.