TRIM Operator

Trims characters from the left, right, or both sides of a string value.

 

Syntax

 

TRIM([[LEADING | TRAILING | BOTH] [value] FROM] value)

 

The TRIM operator has these parts:

 

Part

Description

value

A set of characters to trim and a string value.

 

Remarks

 

Use the TRIM operator to trim characters from the left, right, or both sides of a string value. If the set of characters is omitted the operator trims white space characters. If no LEADING, TRAILING, or BOTH keywords are specified the operator trims both sides of the string value.

 

The TRIM operator is case-sensitive.

 

Examples

 

This example uses the TRIM operator to trim the building number from the address of each customer:

 

SELECT [Address], TRIM(TRIM("1234567890, " FROM [Address])) AS [Trimmed Address] FROM [Customers];

 

This example uses the TRIM operator to remove the first word from the title of each employee (using the English alphabet assuming the data is in English):

 

SELECT [Title], TRIM(TRIM(LEADING "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" FROM [Title])) AS [Trimmed Title] FROM [Employees];