Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SP to replace data in text field

Author  Topic 

safzal1212
Starting Member

11 Posts

Posted - 2009-08-26 : 14:58:02
I have a table with text field and that field have some large text data. In that field I want to search the whole data and replace some values with other values. What is the good way to do it? I suspect we have a system stored procedure to do that!

DeepRedWill
Starting Member

4 Posts

Posted - 2009-08-26 : 15:12:10
Hi there. Your solution depends partly on how much needs to change, but it's likely similar to this:



UPDATE table
SET col_to_change = REPLACE(col_to_change, "bad_data", "good_data");


The REPLACE function is key, and can be nested ad infinitum.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-08-26 : 15:13:28
have a look at UPDATETEXT http://msdn.microsoft.com/en-us/library/ms189466.aspx

also see here: http://msdn.microsoft.com/en-us/library/ms187993.aspx
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-08-26 : 15:16:22
quote:
Originally posted by DeepRedWill

Hi there. Your solution depends partly on how much needs to change, but it's likely similar to this:



UPDATE table
SET col_to_change = REPLACE(col_to_change, "bad_data", "good_data");


The REPLACE function is key, and can be nested ad infinitum.



REPLACE doesn't work on TEXT data type
Go to Top of Page

DeepRedWill
Starting Member

4 Posts

Posted - 2009-08-26 : 15:23:05
Right. I wasn't thinking data types at all, my bad.
Go to Top of Page
   

- Advertisement -