Updated on Kisan Patel
This tutorial will show you how to trim unnecessary space from the string in SQL Server?
To trim unnecessary blank spaces from the string in SQL Server, we use LTRIM
or RTRIM
functions.
Note: To remove all spaces, we can use both LTRIM and RTRIM functions.
DECLARE @myName varchar(50) SET @myName = 'https://csharpcode.org/' 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−