LTRIM
Returns a character expression after the starting space is deleted.
Grammar
LTRIM (character_expression)
Parameters
character_expression
is either a character or a binary data expression. Character_expression can be a constant, variable, or column. The character_expression must be a data type that can be implicitly converted to varchar. Otherwise, use cast to explicitly convert the character_expression.
return type
varchar
Comments
The compatibility level may affect the return value. For more information about compatibility levels, see sp_dbcmptlevel.
Example
The following example uses the LTRIM character to remove the starting space in a character variable.
DECLARE @string_to_trim varchar SET @string_to_trim = ' Five spaces is at the beginning of this string. '
SELECT ' Here is the string without the leading spaces: ' + LTRIM (@string_to_trim) go below is the result set:
------------------------------------------------------------------------here is the string without the leading spaces : Five spaces is at the beginning of this string. (1 row (s) affected)
RTRIM
Returns a string after truncating all trailing spaces.
Grammar
RTRIM (character_expression)
Parameters
character_expression
An expression consisting of character data. Character_expression can be a constant, a variable, or a column of characters or binary data.
return type
varchar
Comments
The character_expression must be a data type that can be implicitly converted to varchar. Otherwise, use the CAST function to explicitly convert the character_expression.
Indicates that the compatibility level may affect the return value. For more information, see sp_dbcmptlevel.
SQL LTrim () and RTrim () functions