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:


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.


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


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