Solved

How to construct SQL Search and Replace query

Posted on 2009-05-08
4
505 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
[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
  • 2
4 Comments
 
LVL 60

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 60

Expert Comment

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

Glad that helped.

Regards,
Kevin
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

691 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