TRIM
removes leading and trailing spaces from a string.
TRIM
can also remove other characters with an optional parameter.
This function can be replaced by combining LTRIM and RTRIM functions.
This example removes leading and trailing spaces from the input string.
SELECT TRIM(' SQL ') AS Trimmed
Trimmed |
---|
SQL |
Syntax for the TRIM function.
TRIM ([characters FROM] string)
[characters FROM ]
is optional and specifies characters to be removed.
[characters FROM ]
is only supported in SQL Server 2017 and newer.
string
-- a string or column name to trim.
SELECT TRIM('#! ' FROM ' #! #SQL ! ') AS Trimmed
Supported in SQL Server 2017 and up.
Trimmed |
---|
SQL |