[!div class=“nextstepaction”] Please help improve SQL Server docs!
Removes the space character char(32)
or other specified characters from the start or end of a string.
TRIM ( [ characters FROM ] string )
characters
Is a literal, variable, or function call of any non-LOB character type (nvarchar
, varchar
, nchar
, or char
) containing characters that should be removed. nvarchar(max)
and varchar(max)
types are not allowed.
string
Is an expression of any character type (nvarchar
, varchar
, nchar
, or char
) where characters should be removed.
Returns a character expression with a type of string argument where the space character char(32)
or other specified characters are removed from both sides. Returns NULL
if input string is NULL
.
By default TRIM
function removes the space character char(32)
from both sides. This is equivalent to LTRIM(RTRIM(@string))
. Behavior of TRIM
function with specified characters is identical to behavior of REPLACE
function where characters from start or end are replaced with empty strings.
The following example removes spaces from before and after the word test
.
Here is the result set.
test
The following example removes a trailing period and trailing spaces.
Here is the result set.
# test
LEFT (Transact-SQL)
LTRIM (Transact-SQL)
RIGHT (Transact-SQL)
RTRIM (Transact-SQL)
STRING_SPLIT (Transact-SQL)
SUBSTRING (Transact-SQL)
String Functions (Transact-SQL)