The SQL Server LTRIM function is a String Function used to remove the empty spaces from the Left hand side of a character expression. This LTRIM function will return VARCHAR or NVARCHAR, and its syntax is shown below.
SELECT LTRIM(Character_Expression, characters)
FROM [Source]
Character_Expression: Please specify the valid Expression on which you want to remove leading empty spaces (performing left trimming). The LTRIM Function will remove the leading blanks from the left side of this expression. This Character_Expression can be a variable, constant, or column of any data type, except image, text, and ntext.
Characters (optional): The LTRIM function has an optional second argument. By default, it trims whitespace at the beginning. However, we can use this argument to left-trim any characters.
SQL Server LTRIM Function Example
The LTRIM Function returns the character expression after removing the empty spaces from the left side of the given expression. The following query will show multiple ways to use this function.
TIP: You can use the SQL CAST to explicitly convert the Character_Expression.
DECLARE @i VARCHAR(50)
SET @i = ' Tutorial Gateway'
SELECT LTRIM(@i) AS Result;
SELECT LTRIM(' Hello T-SQL') AS Result;
SELECT LTRIM(' Free SQL Tutorials at Tutorial Gateway ') AS Result;

The below code is used to declare the VARCHAR variable and assign the string data.
DECLARE @i VARCHAR(50) SET @i = ' Tutorial Gateway'
From the above statement, you can see that we have some leading spaces before the string ‘ Tutorial Gateway’. The following SQL Server SELECT statement will remove those extra spaces from the string variable.
SELECT LTRIM(@i) AS Result;
In the following line, We used the LTRIM function directly on string data.
SELECT LTRIM(' Hello T-SQL') AS Result;
As you see below, we have some leading spaces before and after the string. The following String functions line will remove the extra spaces from only the left side of the specified expression. Refer to the list of SQL Server String Functions from our SQL Server Programming.
SELECT LTRIM(' Free SQL Tutorials at Tutorial Gateway ') AS Result;
Use LTRIM() to remove specified characters
In the example below, we use LTRIM() to remove unwanted digits (1234) from the beginning of a string.
SELECT LTRIM('1234Hello World', '1234')
SELECT LTRIM('1234Hello World', '12')
Hello World
34Hello World
Use LTRIM() to remove a substring from a string
In the query below, we used the LTRIM() function to remove the substring (Tutorial) from a given string. If you observe, there is a case difference between the original string and the second argument. However, LTRIM() is case-insensitive, so it performs left-trim.
SELECT LTRIM('TutorialGateway', 'tutorial')
Gateway
Use the LTRIM() function on Table columns
In this example, we will use the Sql Server LTRIM function on Column Names. Generally, we may get data with some extra spaces due to typing mistakes or any other data entry issues.
If you find such data, you must use this LTRIM or RTRIM to trim those extra spaces. Explore the SQL RTRIM.
SELECT TOP 10 [ProductKey]
,LTRIM([EnglishProductName]) AS [ProductName]
,[Color]
,[ModelName]
,LTRIM([EnglishDescription]) AS [Description]
FROM [AdventureWorksDW2014].[dbo].[DimProduct]
WHERE [EnglishDescription] IS NOT NULL

Use SQL LTRIM Function before joining strings
When you are concatenating strings, you should be very careful with extra spaces. In this example, we will use the LTRIM function along with CONCAT. For this SQL CONCAT, we are going to use the data shown below. If you notice the FirstName and LastName, there are a few empty spaces at the beginning of some names.

The following statement will remove white spaces from the left-hand side of the [FirstName] column and [LastName] column. Please refer to the SQL TRIM and SQL SUBSTRING functions.
SELECT LTRIM([FirstName]) + ' ' + LTRIM([LastName]) AS [FullName]
,[Education]
,[Occupation]
,[YearlyIncome]
,[Sales]
,[HireDate]
FROM [Employee]
