Replace Data in SQL

update tablename set columnName = REPLACE(ColumnName, ‘OriginalData’, ‘NewData’)

This is mostly for myself but always good info. This will replace all the originaldata with the NewData for every row in the table.

Update: I’ve noticed that in SQL2000 this will not work if the column is ntext, so a work around is: (if your data isn’t to long)

update tablename set columnName = REPLACE(cast(columnName as nvarchar(1000)), ‘OriginalData’, ‘NewData’)

 

update: I just ran across this.. If you have triggers setup, remember to add the where clause because if you don’t the update will touch (not change, but touch) each record and the trigger for them will them run.

 

update tablename set columnName = REPLACE(ColumnName, ‘OriginalData’, ‘NewData’)

where blah = ‘blahblah’

Technorati Tags:

     

Leave a Reply