Search and replace part of string in database

151,027

Solution 1

I think 2 update calls should do

update VersionedFields
set Value = replace(value,'<iframe','<a><iframe')

update VersionedFields
set Value = replace(value,'> </iframe>','</a>')

Solution 2

You can do it with an UPDATE statement setting the value with a REPLACE

UPDATE
    Table
SET
    Column = Replace(Column, 'find value', 'replacement value')
WHERE
    xxx

You will want to be extremely careful when doing this! I highly recommend doing a backup first.

Solution 3

I was just faced with a similar problem. I exported the contents of the db into one sql file and used TextEdit to find and replace everything I needed. Simplicity ftw!

Share:
151,027
Zooking
Author by

Zooking

Sitecore developer with lots of different CMS-experience.

Updated on July 05, 2022

Comments

  • Zooking
    Zooking almost 2 years

    I need to replace all iframe tags, stored as nvarchar in my database. I can find the entries using the following sql-question:

    SELECT * FROM databasename..VersionedFields WHERE Value LIKE '%<iframe%'
    

    Say I want to replace the following code segment:

    code before iframe <iframe src="yadayada"> </iframe> code after iframe
    

    With this:

    code before iframe <a>iframe src="yadayada"</a> code after iframe
    
  • Giacomo Pigani
    Giacomo Pigani over 10 years
    Here there are more info about it