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
Summary

Instruction

Great! But what if you want to remove a set of characters from the beginning and end of a string? You can also use TRIM() to do that. This requires an additional argument: a string containing the characters you want to remove (the first argument) and the actual text (the second argument).

Let's remove the following characters from a sentence: ., ?, , and !

SELECT TRIM(N' !?.' FROM N'?What is the best way to do it? !.');

Notice that this function contains a FROM between the list of characters to remove and the text.

This is the result you obtain:

N'What is the best way to do it'

As you can see, all specified characters were removed from the beginning and end of the text.

Exercise

Remove all leading and trailing spaces and zeros from the item names in the Item table. Name the column After.

Stuck? Here's a hint!

Use TRIM() with the folowing arguments: a string listing the characters to remove, FROM, and the column with the names.