LTRIM (Transact-SQL)

 

THIS TOPIC APPLIES TO: yesSQL Server (starting with 2008)yesAzure SQL DatabaseyesAzure SQL Data Warehouse yesParallel Data Warehouse

Returns a character expression after it removes leading blanks.

Topic link icon Transact-SQL Syntax Conventions

-- Syntax for SQL Server, Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse  
  
LTRIM ( character_expression )  

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.

varchar or nvarchar

The following example uses LTRIM to remove leading spaces from a character variable.

DECLARE @string_to_trim varchar(60);  
SET @string_to_trim = '     Five spaces are at the beginning of this  
   string.';  
SELECT 'Here is the string without the leading spaces: ' +   
   LTRIM(@string_to_trim);  
GO  

Here is the result set.

------------------------------------------------------------------------  
Here is the string without the leading spaces: Five spaces are at the beginning of this string.               
  
(1 row(s) affected)  

The following example uses LTRIM to remove leading spaces from a character expression.

-- Uses AdventureWorks  
  
SELECT LTRIM('     Five spaces are at the beginning of this string.') FROM dbo.DimCustomer;  

Here is the result set.

---------------------------------------------------------------

Five spaces are at the beginning of this string.

Data Types (Transact-SQL)
String Functions (Transact-SQL)

Community Additions

ADD
Show: