SQL TRIM Functions - LTRIM and RTRIM

TRIM Functions in SQL Server

TRIM function in SQL remove all specified trim char from beginning and ending of the string.
In SQL Server, the LTRIM function removes all space characters from the left-hand side of a string and RTRIM function removes all from right.

The syntax for the functions are as follows:

LTRIM(String)
RTRIM(String)


Note: The String parameter that is passed to the functions can be a column name, a variable, a literal string or the output of a user defined function or scalar query.


Examples:

SELECT LTRIM('  ravi bhushan')
SELECT RTRIM( [
column]  ) FROM  [table]
UPDATE  [table]  SET  [column] = LTRIM(RTRIM( [column] ))

More...

SELECT LTRIM('   binkod.in');
Ouput: 'binkod.in'

SELECT LTRIM('   binkod.in   ');

Ouput: 'binkod.in   '

SELECT RTRIM('binkod.in   ');
 
Ouput: 'binkod.in'

Post a Comment

If you have any questions or concerns, please let me know.

Previous Post Next Post