1

I want to replace all the values within a column that are:

 Boston, MA (2 space) 

with:

 Boston, MA (1 space) 

I have gotten as far as:

select [Location], replace(replace(replace([Location],' ','<>'),'><',''),'<>',' ') from [Table] 

How can I replace the values in the [location] column with the result of the query above?

note: there are other values in the [location] column, eg.

Hong Kong London, UK 
2
  • 8
    replace(field, 'spacespace', 'space')? Commented Sep 2, 2014 at 20:29
  • 1
    Take a look at this article. sqlservercentral.com/articles/T-SQL/68378 It explains how to replace multiple spaces with a single space. If you only have 2 spaces then the fine code that M.Ali posted will work great. If however, you find that you have multiple spaces the article I linked shows a great way to deal with that. Commented Sep 2, 2014 at 21:34

1 Answer 1

1
select [Location], replace([Location],' ', ' ') from [Table] 

to update the column

UPDATE [Table] SET [Location] = replace([Location],' ', ' ') 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.