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

You now know two functions that remove either leading or trailing spaces. Sometimes you need to remove both leading and trailing spaces. With SQL Server 2017, you can do this with the TRIM() function. It requires one parameter. Have a look at an example:

SELECT TRIM(N' Martin Smith      from England   .   ');

After calling this function, you'd get:

'Martin Smith      from England   .'

Exercise

Remove all leading and trailing spaces from the item names in the Item table. For each item, show the original item name (name the column Before) and the item name without leading and trailing spaces (name the column After). In order to see the difference, put an asterisk (*) on both sides of the two values.

Stuck? Here's a hint!

Use TRIM() with column Name as an argument. Don't forget to concatenate the columns with asterisks on both sides: N'*' + Name + N'*'.