Learn Sql Server   Learn Sql Theory   Learn Sql

 
Chapter 1
Chapter 2

Sql Server Reverse Function

Sql Server LTRIM RTRIM

Sql Server CharIndex

Using DML Triggers and Transactions

Sql Server Length

Sql Server Like

Sql Server Cast

Sql Server STR Function

Sql Server Date Function

Sql Server Row-Number

Sql Server Partition By

Sql Server Rank

Sql Server DENSE_RANK

Sql Server NTILE

Sql Server Union

Sql Server Union All

Sql Server Intersect

Sql Server Except

Sql Server IN operator

Sql Server Not IN

Sql Server Exists Function

Sql Server Not Exists

Sql Server Between

Sql Server NOT Between

Sql Server Case Statement

Sql Server IF ELSE

Sql Server Group by

Sql Server Having

Sql Server REPLICATE

Sql Server PATINDEX

DIFFERENCE() and SOUNDEX() string Functions

Evaluating Whether an Expression Is a Date or Is Numeric

Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 12
Chapter 13
Chapter 14
Chapter 15
Chapter 16

LTRIM and RTRIM Functions in Sql Server

Syntax for LTRIM and RTRIM

LTRIM(str)
RTRIM(str)
Sponsored links

Ltrim Function in Sql Server


SELECT LTRIM(' Ranu') AS Names

which produces:

Names
Ranu


(1 row(s) affected)

LTRIM in sql server removes blanks from the beginning (left) of a string. For example, if three blank spaces appear to the left of a string such as ' Ranu', you can remove the blank spaces with the above query.

It does not matter how many blank spaces precede the non-blank character. All leading blanks will be excised.



Rtrim Function in Sql Server

SELECT RTRIM('Ranu ') + Saha AS Names


This query produces:

Names
Ranu Saha


(1 row(s) affected)

Similarly, RTRIM in sql server removes blanks from the end (right) of a string. For example, if blank spaces appear to the right of Ranu in the names column, you could remove the blank spaces using the RTRIM, and then concatenate "Saha" with the + sign, as shown above.

Sponsored Links