Solved

How to replace dashes with spaces?

Posted on 2013-06-02
8
438 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
ID: 39213993
Try this
Replace(city,'-',' ')
0
 
LVL 7

Expert Comment

by:Ross Turner
ID: 39213994
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
ID: 39213999
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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 16

Accepted Solution

by:
Surendra Nath earned 500 total points
ID: 39214004
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
 
LVL 7

Expert Comment

by:Ross Turner
ID: 39214007
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
ID: 39214010
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
ID: 39214014
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
ID: 39214032
Errr I gave the same solution in post 2 and not even shared points ????
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL create line numbers for data sampling 11 27
sql server query 18 36
Shrink multiple databases at once 4 24
SQL View / Qtry 3 10
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

856 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