Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

How to replace dashes with spaces?

My table Populations has a column named City.
 
About 1000 entries for "City" contain city names that have dashes in them.
I want to replace all dashes with spaces.  How can I quickly write a query that selects all city like '%-%' and update them with a space to replace the dash?  Thank you!
0
arthurh88
Asked:
arthurh88
  • 5
  • 2
1 Solution
 
Ross TurnerManagement Information Support AnalystCommented:
Try this
Replace(city,'-',' ')
0
 
Ross TurnerManagement Information Support AnalystCommented:
Once you happy with a select
Replace(city,'-',' ')

You could do an update

Update your table
Set city = Replace(city,'-',' ')

That should get you sorted
0
 
arthurh88Author Commented:
how do i do the select statement and the replace together?  im not sure how to word a select and an update at the same time, i want to both select all instances of city that contain a dash and then update the record to replace the dash with space.
0
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

 
Surendra NathTechnology LeadCommented:
There is no need to do a select, if you want to do an update here.
this should do it

Update <your table>
Set city = Replace(city,'-',' ')

Open in new window

0
 
Ross TurnerManagement Information Support AnalystCommented:
Below will find all - and return
And show original and replaced

Select
City as originalcity,
Replace(city,'-',' ') as replacedcityname
From yourtable
Where city like '%-%'

Then once your happy create a new query to update youtable
Set city = Replace(city,'-',' ')
Where city like '%-%'
0
 
Ross TurnerManagement Information Support AnalystCommented:
Hey Neo_jarvis i thought it would be better to let him see what he changing before changing..... Then go into an update.

But indeed you can bowl straight into the update statement... If your confident it going to give you the right outcome.
0
 
arthurh88Author Commented:
wow how easy was that.   thanks....i guess I should have figured that out, but I will know next time.  perfect
0
 
Ross TurnerManagement Information Support AnalystCommented:
Errr I gave the same solution in post 2 and not even shared points ????
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now