Tuesday, June 1, 2010

Search & Replace values in MS-SQL 2005/20088 text fields

Starting from MS-SQL 2005 there is a new SQL function called "REPLACE" and you can use it to replace values in text fields (varchar/nvarchar/nchar...).

just put the right table names and the right column names in the following code:

update TableTable
set ArticleContent = (
SELECT REPLACE(TargetColumn, 'old value', 'new value')
FROM TargetTable Table_In
where Table_Outside.ArticleId = Table_In.ArticleId
)
from TargetTable Table_Outside

No comments:

Post a Comment