SQLTeam.com | Weblogs | Forums

Remove the extra space in between texts


#1

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:
ABCD EFGHIJKLM

Result I need:
ABCD EFGHIJKLM

Thanks all


#2

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

#3

Hi James,

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

Here is what the result set I need:
ABCD EFGHIJKLM

I used the underline to represent the space.


#4
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.


#5

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