Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sql replace statement

Posted on 2014-02-06
3
Medium Priority
?
315 Views
Last Modified: 2014-02-06
Hi,
I'm using SQL server 2005
I entered in a bunch of data but forgot to clean one of the fields before I did.
The field has some dashes in it   " - ".

I don't know how to remove the dash in each of the fields by using only SQL. I could do it with perl but I'm wondering how I would loop through all the records and replace the dash (-) with nothing.

So for arguments sake the field name is  address

Something like
 
Foreach record in table AddressList
    Get the value of the field 'address'
    Remove dash(es) if present
    end foreach

Thanks,
Nacht
0
Comment
Question by:nachtmsk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 39839280
Use the REPLACE() function.

REPLACE ( string_expression , string_pattern , string_replacement )
0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 39839297
UPDATE YourTable
SET YourColumn = REPLACE(YourColumn, '-', '')
0
 
LVL 1

Author Closing Comment

by:nachtmsk
ID: 39839475
Thanks, that worked perfectly.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

721 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