![]() | |||||
![]() |
|||||||||||||
|
Search and Replace in a Text Column
SQL Server has a replace function, but it doesn't work on "text" columns. SQL Server seems to address this with a new varchar(max) datatype, but those of us still using SQL Server 2000 still need a solution. The following stored procedure should do the trick. The seed of the idea for this came from the following page:
http://www.sqlteam.com/article/search-and-replace-in-a-text-column My version puts the code in a stored procedure, replaces all instances of the string, escapes any wildcard characters that might be in the string, and also prints out the number of replacements that are done. It is limited in that it won't work if the new text contains the old text, because that would cause an infinite loop, but maybe we'll be using varchar(max) before we need to do that! - David (dave@modernsignal.com) Usage: EXEC usp_utility_replacetext 'Content','htmlContent','oldtext','newtext' CREATE PROCEDURE dbo.usp_utility_ReplaceText |
July 15, 2008 --
May 22, 2008 --
May 13, 2008 --
April 2008 --
April 2008 --
March 7, 2008 --
January 30, 2008 --
|
||||||||||||