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.