SQLTeam.com | Weblogs | Forums

Remove the extra space in between texts


Hello all sql expert,

How do I remove the extra space in between texts? Below is my query:

Select Column1 + column2
from Tbl

Result set:

Result I need:

Thanks all


In your post, "Result set" and the "Results I need" look the same, so not clear what you are trying to accomplish.

If you want to remove spaces from the resulting string, you can do the following:

Select REPLACE(Column1 + column2, ' ','')
from Tbl


Hi James,

You are correct.
Here is the result set from query:

Here is what the result set I need:

I used the underline to represent the space.

Select RTRIM(CAST(Column1 AS VARCHAR(256)) + ' ' + LTRIM(CAST(column2 AS VARCHAR(256))
from Tbl

I arbitrarily picked 256 as the maximum length of the columns for column1 and column2. That may or may not be sufficient depending on the data type of those columns. If they are longer, increase the 256 appropriately.


Thanks James, you are a super sql expert !!!