Skip to content

Latest commit

 

History

History
100 lines (77 loc) · 3.7 KB

File metadata and controls

100 lines (77 loc) · 3.7 KB
description LTRIM (Transact-SQL)
title LTRIM (Transact-SQL) | Microsoft Docs
ms.custom
ms.date 02/27/2017
ms.prod sql
ms.prod_service database-engine, sql-database, synapse-analytics, pdw
ms.reviewer
ms.technology t-sql
ms.topic reference
f1_keywords
LTRIM
LTRIM_TSQL
dev_langs
TSQL
helpviewer_keywords
leading blanks
deleting blank spaces
characters [SQL Server], blanks
removing blank spaces
LTRIM function
blank characters [SQL Server]
ms.assetid 369ed340-1a09-4597-a9eb-6720156cd39a
author markingmyname
ms.author maghan
monikerRange >=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current

LTRIM (Transact-SQL)

[!INCLUDE sql-asdb-asdbmi-asa-pdw]

Returns a character expression after it removes leading blanks.

Topic link icon Transact-SQL Syntax Conventions

Syntax

LTRIM ( character_expression )  

[!INCLUDEsql-server-tsql-previous-offline-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.');  

[!INCLUDEssResult]

---------------------------------------------------------------  
 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  

[!INCLUDEssResult]

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)