Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » String FunctionsRSS Feeds

LTRIM Function

Posted By: Sarita Patel     Category: SQL Server     Views: 6358

This article explains LTRIM function of sql server with examples.

LTRIM function is used to remove leading spaces from specified string. 


Syntax of LTRIM Function :

LTRIM (character_expression)

character_expression is an expression of character or binary data. character_expression can be a constant, variable, or column.  

Return type of LTRIM function is varchar.


Examples of LTRIM Function :

Example 1 : Use of LTRIM function in select clause

SELECT LTRIM('       Syntax-Example')  

Output
Syntax-Example

Above example returns removed leading space string.


Example 2 : Use of LTRIM function to display field value of table.

SELECT LTRIM(ContactName) AS 'Customer Name'    
FROM   Customers

Output
Customer Name
Maria Anders
Ana Trujillo
Antonio Moreno
Thomas Hardy
Christina Berglund
Hanna Moos

Above example displays customer name with removed leading spaces if any.



Example 3 : Use of LTRIM function in where clause

SELECT ContactName, CompanyName
FROM   Customers
WHERE  LTRIM(ContactName) = LTRIM('   ana trujillo')

Output
ContactName     CompanyName
Ana Trujillo        Ana Trujillo Emparedados y helados

Above example compares contactname with specified string after removing leading spaces.
 
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on LTRIM Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of LTRIM Function is from United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!