Open In App

LTRIM() Function in SQL Server

Last Updated : 16 Dec, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

LTRIM() function helps to return remove all the space characters found on the left-hand side of the string.

Syntax :

LTRIM(string, [trim_string])

Parameter :

  • string – The string from which the leading space character would be removed.
  • trim_string – It is an optional parameter that specifies the characters to be removed from the given string.

Returns :
The function will return the string after removing all left-hand side space characters.

Applicable to the following versions of SQL Server :

  • SQL Server 2017
  • SQL Server 2016
  • SQL Server 2014
  • SQL Server 2012
  • SQL Server 2008 R2
  • SQL Server 2008
  • SQL Server 2005

Example 1 :
The basic usage of the LTRIM() function.

SELECT LTRIM('       GeeksforGeeks');

Output :

GeeksforGeeks

Example 2 :
Using LTRIM() function with a variable.

DECLARE @str VARCHAR(50)
SET @str = '     Have a nice time ahead!!'
SELECT LTRIM(@str);

Output :

Have a nice time ahead!!

Example-3 :
Use of “trim_space” in LTRIM() function.

SELECT LTRIM (‘000325400’, ‘0’);

Output :

325400

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads