LTRIM (Transact-SQL)
Applies to:
SQL Server (all supported versions)
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Analytics Platform System (PDW)
Returns a character expression after it removes leading blanks.
Transact-SQL Syntax Conventions
Syntax
LTRIM ( character_expression )
Note
To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.
Arguments
character_expression
Is an expression of character or binary data. character_expression can be a constant, variable, or column. character_expression must be of a data type, except text, ntext, and image, that is implicitly convertible to varchar. Otherwise, use CAST to explicitly convert character_expression.
Return Type
varchar or nvarchar
Examples
A. Simple example
The following example uses LTRIM to remove leading spaces from a character expression.
SELECT LTRIM(' Five spaces are at the beginning of this string.');
Here is the result set.
---------------------------------------------------------------
Five spaces are at the beginning of this string.
B: Example using a variable
The following example uses LTRIM to remove leading spaces from a character variable.
DECLARE @string_to_trim VARCHAR(60);
SET @string_to_trim = ' 5 spaces are at the beginning of this string.';
SELECT
@string_to_trim AS 'Original string',
LTRIM(@string_to_trim) AS 'Without spaces';
GO
Here is the result set.
Original string Without spaces
--------------------------------------------------- ---------------------------------------------
5 spaces are at the beginning of this string. 5 spaces are at the beginning of this string.
See Also
LEFT (Transact-SQL)
RIGHT (Transact-SQL)
RTRIM (Transact-SQL)
STRING_SPLIT (Transact-SQL)
SUBSTRING (Transact-SQL)
TRIM (Transact-SQL)
Data Types (Transact-SQL)
String Functions (Transact-SQL)