TRIM Function

Removes leading characters, trailing characters, or both from a character string.

Category: Character
Returned data type: VARCHAR NVARCHAR

Syntax

Arguments

BOTH | LEADING | TRAILING

specifies whether to remove the leading characters, the trailing characters, or both.

Default BOTH

trim-character

specifies one character to remove from column. Enclose a literal character in single quotation marks. If trim-character is not specified, the TRIM function trims all blank spaces, not just one character.

Default Blank
Data type CHAR, VARCHAR, NVARCHAR

column

is any valid expression that evaluates to a column name.

Details

The TRIM function is useful for trimming character strings of blanks or other characters before they are concatenated.

Example

Table: AFEWWORDS
The following statements illustrate the TRIM function:
Statements
Results
select trim(word1) from afewwords;
*some/
*every*
*no*
select trim(both '*' from word1) from afewwords;
some
every
no
select trim(leading '*' from word1) from afewwords;
some/
every*
no*
select trim(trailing '*' from word1) from afewwords;
*some/
*every
*no

See Also

Functions: