[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Sql string replace

Posted on 2011-05-07
2
Medium Priority
?
280 Views
Last Modified: 2012-05-11
I would like to find and replace string in a column.
For example: TableA   MyColumn (varchar(50))
Replace USA with GB
Id=2   MyColumn: GER, USA, INDIA
Id=3   MyColumn: CHINA, INDIA, USA
The result should be:  
Id=2  MyColumn: GER, GB, INDIA
Id=3  MyColumn: CHINA, INDIA, GB
How is best to do this?
0
Comment
Question by:johnkainn
2 Comments
 
LVL 9

Accepted Solution

by:
kaminda earned 252 total points
ID: 35712725
You can use the Replace function in SQL to do this. It is the easiest and fastest way to do this,

SELECT REPLACE(MyColumn,'USA', 'GB') FROM yourTableName
0
 
LVL 12

Assisted Solution

by:Adam
Adam earned 248 total points
ID: 35713879
The above solution works if you want to leave the data unchanged

If you want to actually change the data, use:

update TableA set MyColumn = REPLACE(MyColumn,'USA', 'GB')

Open in new window

0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
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.
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

864 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