MS SQL Server LTRIM() Function

Sometime you may need to trim leading blank space character from your desired text in MS SQL Server. There is a function called LTRIM in MS SQL Server by which you can do this. LTRIM function returns a character expression after removing it’s leading blanks.

Let’s see the function structure:

LTRIM(character_expression)

In this function there is only one parameter. Parameter character_expression can be character or binary data. character_expression can be a constant, variable, or column. LTRIM function returns a character expression as VARCHAR or NVARCHAR after removing it’s leading blanks.

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

DECLARE @input varchar(60);
SET @input = '   Minhajur Rahman Khan'; SELECT @input AS 'before_ltrim', LTRIM(@input) AS 'after_ltrim';

Here is the result set.

before_ltrim after_ltrim
   Minhajur Rahman Khan Minhajur Rahman Khan

I have an another post MS SQL Server String Related Functions where you will learn about different string related functions of MS SQL Server.

In this tutorial, I have shown you how to trim leading blank space character from your desired text in MS SQL Server. Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page http://www.facebook.com/freetechtrainer and stay connected.

Add a Comment