SQL Server LTRIM() Function: Removes Leading Spaces
In SQL Server, the LTRIM()
function removes the leading space from the beginning of the specified string and returns it.
LTRIM(character_expression)
Parameters
character_expression: A string of character or binary data. It can be a constant, variable, or table column.
Note: character_expression must be of a data type, except text, ntext, and image, that is implicitly convertible to varchar.
Return Value
A string of varchar or nvarchar.
Example 1:
In the following example, the leading spaces in a string are trimmed using the LTRIM()
function.
SELECT ' Remove leading spaces' AS InputString,
LTRIM(' Remove leading spaces') AS Result
Example 2:
Consider the following Address
column with AddressID = 5
row has leading spaces.
Use the LTRIM()
function to trim the leading spaces from the Address
column, as shown below.
SELECT AddressID, LTRIM(Address) AS Address FROM Address