SQL Server/T-SQL/String Functions/LTRIM

Материал из SQL эксперт
Перейти к: навигация, поиск

LTRIM: removes leading spaces from a string

1> -- LTRIM: removes leading spaces from a string.
2>
3> DECLARE @STRING_WITH_SPACES VARCHAR(30)
4> DECLARE @STRING_WITHOUT_SPACES VARCHAR(30)
5> SET @STRING_WITH_SPACES = " www.sqle.ru"
6>
7> SET @STRING_WITHOUT_SPACES = LTRIM(@STRING_WITH_SPACES)
8>
9> SELECT @STRING_WITH_SPACES
10> SELECT @STRING_WITHOUT_SPACES
11> GO
------------------------------
 www.sqle.ru
(1 rows affected)
------------------------------
www.sqle.ru
(1 rows affected)
1>



LTRIM: trim the white space to the left

12>
13>
14> -- LTRIM() and RTRIM() Functions
15>
16> -- Return a string with white space (spaces) trimmed
17>
18> DECLARE @Value1 Char(10), @Value2 Char(10) SET @Value1 = "One"
19> SET @Value2 = "Two"
20> SELECT @Value1 + @Value2
21> SELECT CONVERT(VarChar(5), LEN(@Value1 + @Value2)) + " characters long."
22> SELECT RTRIM(@Value1) + RTRIM(@Value2)
23> SELECT CONVERT(VarChar(5), LEN(RTRIM(@Value1) + RTRIM(@Value2)))
24>        + " characters long trimmed."
25> GO
--------------------
One       Two
(1 rows affected)
----------------------
13 characters long.
(1 rows affected)
--------------------
OneTwo
(1 rows affected)
------------------------------
6 characters long trimmed.
(1 rows affected)
1>
2>