To trim unnecessary blank spaces from the string in SQL Server, we use LTRIM or RTRIM functions.
LTRIM
– removes the left side spaces, if anyRTRIM
– removes the right side spaces, if anyTo remove all spaces, we can use both LTRIM and RTRIM functions.
DECLARE @myName varchar(50) SET @myName = ' ITFunda.com ' SELECT @myName SELECT LTRIM(@myName), RTRIM(@myName), LTRIM(RTRIM(@myName))
Notice the output of above code snippet below.
In first case, the output is coming along with left side and right side blank space.
In the 2nd result set