Solved

How to replace dashes with spaces?

Posted on 2013-06-02
8
424 Views
Last Modified: 2013-06-02
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
Comment
Question by:arthurh88
  • 5
  • 2
8 Comments
 
LVL 7

Expert Comment

by:Ross Turner
Comment Utility
Try this
Replace(city,'-',' ')
0
 
LVL 7

Expert Comment

by:Ross Turner
Comment Utility
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
 

Author Comment

by:arthurh88
Comment Utility
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
 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 7

Expert Comment

by:Ross Turner
Comment Utility
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
 
LVL 7

Expert Comment

by:Ross Turner
Comment Utility
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
 

Author Closing Comment

by:arthurh88
Comment Utility
wow how easy was that.   thanks....i guess I should have figured that out, but I will know next time.  perfect
0
 
LVL 7

Expert Comment

by:Ross Turner
Comment Utility
Errr I gave the same solution in post 2 and not even shared points ????
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now