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 2000 Forums
 SQL Server Development (2000)
 Search and replaice?

Author  Topic 

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2003-01-29 : 16:11:54
Is there a way to seach all the tables in a database for certain word(s) and replace them with another word(s)?

--
For those with wings, fly to your dreams

Dearms are what are found at the end of reality, and your reality if what is found at the end of your dreams.

SamC
White Water Yakist

3467 Posts

Posted - 2003-01-29 : 16:19:31
There are sophisticated tools that'll do the whole table or db, but here's a simple query that will do a column using REPLACE

UPDATE Mytable
SET MyColumn = REPLACE(MyColumn, 'search text', 'replace text')

Be careful..

Sam

Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2003-01-29 : 17:25:09
You can use the information_schema views to obtain generate dynamic sql that will execute updates for every table especially if the column names and the number of columns differ.

1. Generate temp table with table, column information from information_schema views.

2. Loop over those generating dynamic sql and executing.

You can also have a look up table for all the replacements and use a join in your update statement so that you know what to replace in which table in case you have multiple scenarios.



Go to Top of Page

mohdowais
Sheikh of Yak Knowledge

1456 Posts

Posted - 2003-01-30 : 07:37:20
Vyas has an excellent article on his website to do just that:
[url]http://vyaskn.tripod.com/sql_server_search_and_replace.htm[/url]

Enjoy

OS

Go to Top of Page

Eagle_f90
Constraint Violating Yak Guru

424 Posts

Posted - 2003-01-30 : 11:49:43
Great thanks! That was what I was looking for.

--
For those with wings, fly to your dreams

Dearms are what are found at the end of reality, and your reality if what is found at the end of your dreams.
Go to Top of Page
   

- Advertisement -