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’)

Technorati Tags:

Related Tek-Works Posts:

     

Leave a Reply