SQL Server LTRIM() Function

The LTRIM() function in SQL Server is used to remove leading spaces (spaces at the beginning) from a string. This is a very common function for data cleaning and preparing strings for comparison or other operations.



LTRIM(): Definition and Usage

Extra whitespace at the beginning of a string can sometimes cause unexpected results in comparisons and other string manipulations. LTRIM() provides a simple way to remove these leading spaces, leaving you with the core string data. Spaces that appear within the string or at the end of the string are not affected by this function.

Syntax

Syntax

LTRIM(string)
      

Parameter Values

Parameter Description
string The string from which you want to remove leading spaces. This is required.

Related Function

For removing trailing spaces (spaces at the end of a string), use the RTRIM() function.

Example

Removing Leading Spaces

This example removes the leading spaces from the string " SQL Tutorial".

Syntax

SELECT LTRIM('    SQL Tutorial') AS LeftTrimmedString;
      
Output

SQL Tutorial