Solved

How to construct SQL Search and Replace query

Posted on 2009-05-08
4
478 Views
Last Modified: 2012-05-06
I need a sql query that will search and replace the following string of text inside a field in my database table.  I want to replace the string ' with the single quote character.  Right now, I have a bunch of LastName fields that look like this:

D'Antonio
O'Block
O'Brien
O'Donnell
O'Flaherty

Again, I just want to get rid of that HTML equivalent and use the literal single quote character instead.

TIA for assistance in constructing this query!
0
Comment
Question by:dstjohnjr
  • 2
4 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 24340250
UPDATE your_table_name
SET your_field_name = REPLACE(your_field_name, ''', '''')
WHERE your_field_name LIKE '%'%'
0
 
LVL 13

Expert Comment

by:usachrisk1983
ID: 24340251
If REPLACE is still a valid function in MSSQL 2005 then this should work.  Backup your table first or try in test!

update tblName

   set lastName = Replace(lastName, "&#39", "'")

 where lastName like '%#39#%';

Open in new window

0
 

Author Closing Comment

by:dstjohnjr
ID: 31579645
Had to give full points to this solution since A) it came in first, B) was the full working solution and C) the other solution did not work due to double quotes being used and not single quotes in the replace statement.  Thanks for expert assistance!
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24340666
You are most welcome.

Glad that helped.

Regards,
Kevin
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Copy Database Wizard 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.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

912 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

21 Experts available now in Live!

Get 1:1 Help Now