How to Trim Strings

In order to trim spaces MS-SQL Server provides 3 main functions: trim which removes spaces from the start and the end of any string. The functions ltrim and rtrim allow to remove spaces only in the start(left) or the end(right) of the string.

select 	trim(' hello    ')      as trim, 
        'x'+ltrim(' hello    ') as ltrim, 
        rtrim(' hello    ')+'x' as rtrim;
trim ltrim rtrim
"hello" "xhello    " " hellox"

IN THIS PAGE