Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

TRIM

Example

Trimming removes spaces or specified characters from both the beginning and end of a string.

SELECT TRIM(‘     SQL Tutorial!     ‘AS TrimmedString;

Definition and Usage

The TRIM() function removes either space characters or specified characters from both the beginning and end of a string.

By default, it removes leading and trailing spaces.

Note: Consider using LTRIM() to remove leading spaces and RTRIM() to remove trailing spaces specifically.

Syntax

TRIM([characters FROM ]string)

Parameter Values

Parameter

Description

Characters FROM

Optional. Specify specific characters to remove from the string.

string

Required. The string from which spaces or characters should be removed.

Technical Details

Works in:

 Available in SQL Server from 2017 onward and in Azure SQL Database.

More Examples

Example

Remove specified characters and spaces from a string.

SELECT TRIM(‘#! ‘ FROM ‘    #SQL Tutorial!    ‘AS TrimmedString;