SQL LTRIM Function (Transact SQL)

By: Kris Wenzel   |   Updated: March 6, 2022  
Works With: 

The SQL LTRIM function removes the leading blank spaces from the input character expression.


The LTRIM function returns a character expression after removing all the blank spaces from the left side of the input expression.

SQL LTRIM Usage Notes

The input expression should be explicitly convertible to a varchar value. It can be a character or a binary value but cannot be an image or a text value. However, the cast function can be used to explicitly convert the input data type to varchar.

The return type of the LTRIM function is varchar or nvarchar


LTRIM (input_expression)

SQL LTRIM Examples

The following query shows the simple usage of an LTRIM function.

It removes all the leading blank spaces.

The following query uses the AdventureWorks2019 database.

This query removes all the leading blank spaces in the AddressLine1 column values.

IF you’re hard pressed for why you would want to use this function consider this scenario:

The former DBA imported data “right justified” text into a CHAR(20) column names State. You now need to query this data. reliably. If you simply cast ‘ TEXAS’ as VARCHAR the spaces continue to vex you!

To get around this you can write the following to retrieve all cities in Texas:

 FROM City

See Also

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}