Overview
The LTRIM function is used to remove the leading spaces from a string of characters or character expressions. L is for left and TRIM means to remove unwanted leading spaces.
Explanation
Syntax
LTRIM(expression)Parameters
- expression – this is the string or expression with leading spaces that you want to left trim.
Simple LTRIM Example
The following example will LTRIM the leading characters only even though there are additional spaces in the string.
SELECT LTRIM(' What a wonderful world ')
LTRIM Example Using Table Columns
The following example shows how to remove any leading spaces from a column.
SELECT LTRIM([AddressLine1]) as addressline
FROM [Person].[Address]
Example with LTRIM and CONCAT
The following example show what happens if we use LTRIM and CONCAT to concatenate strings.
- The first column “example1”, the CONCAT id done first and then the LTRIM.
- The second column “example2”, the LTRIM is done first and then the CONCAT.
DECLARE @string1 varchar(30)=' this is the first message'
DECLARE @string2 varchar(30)=' this is the second message'
SELECT LTRIM(CONCAT(@string1,@string2)) example1,
CONCAT(LTRIM(@string1),LTRIM(@string2)) example2Example1 shows the leading spaces for string1 have been removed, but the leading spaces for string 2 remain.
Example2 shows the leading spaces for both string1 and string2 have been removed.

Additional Information

Daniel Calbimonte is a Microsoft Most Valuable Professional, Microsoft Certified Trainer and Microsoft Certified IT Professional for SQL Server. He is an accomplished SSIS author, teacher at IT Academies and has over 10 years of experience as a QE and developer for SQL Server related software. He has worked for the government, oil companies, web sites, magazines and universities around the world. Daniel also regularly speaks at SQL Servers conferences and blogs.
- MSSQLTips Awards: Author of the Year Contender – 2015-2018, 2022, 2023 | Champion (100+ tips) – 2018


