SQL Server/T-SQL Tutorial/String Functions/LTRIM — различия между версиями

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

Версия 13:46, 26 мая 2010

LTRIM Removes leading spaces from a string.

4>
5> DECLARE @STRING_WITH_SPACES VARCHAR(30)
6> DECLARE @STRING_WITHOUT_SPACES VARCHAR(30)
7> SET @STRING_WITH_SPACES = " www.sqle.ru"
8>
9> SET @STRING_WITHOUT_SPACES = LTRIM(@STRING_WITH_SPACES)
10>
11> SELECT @STRING_WITH_SPACES
12> SELECT @STRING_WITHOUT_SPACES
13> GO
------------------------------
 www.sqle.ru
(1 rows affected)
------------------------------
www.sqle.ru
(1 rows affected)
1>


Removing Leading Blanks

6>
7> SELECT LTRIM(" www.sqle.ru sqle.")
8> GO
-----------------------
www.sqle.ru sqle.
(1 rows affected)


select LTRIM(" SQL Server ")

3>
4> select LTRIM(" SQL Server ")
5> GO
------------
SQL Server
(1 rows affected)
1>


The LTRIM() and RTRIM() Functions

4> DECLARE @Value1 Char(10), @Value2 Char(10) SET @Value1 = "One"
5> SET @Value2 = "Two"
6> SELECT @Value1 + @Value2
7> SELECT CONVERT(VarChar(5), LEN(@Value1 + @Value2)) + " characters long."
8> SELECT RTRIM(@Value1) + RTRIM(@Value2)
9> SELECT CONVERT(VarChar(5), LEN(RTRIM(@Value1) + RTRIM(@Value2)))
10>  " characters long trimmed."
11> GO
--------------------
One       Two
(1 rows affected)
----------------------
13 characters long.
(1 rows affected)
--------------------
OneTwo
(1 rows affected)
 characters long trimmed.
-------------------------
6
(1 rows affected)