SQL LTrim () and RTrim () functions

Source: Internet
Author: User
Tags rtrim

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.