Link to home
Start Free TrialLog in
Avatar of dstjohnjr
dstjohnjrFlag for United States of America

asked on

How to construct SQL Search and Replace query

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!
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of dstjohnjr

ASKER

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!
You are most welcome.

Glad that helped.

Regards,
Kevin