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)
 Update in stored procedure while looping through a cursor

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-11-17 : 10:30:00
envirodat writes "I need to do a search and replace for string values in database where the colums could contain the data in many tables and different column names. Below is the SQL I have so far.


DECLARE @CrsrVar Cursor
@SQL nvarchar(4000)
Set @CrsrVar = Cursor for
SELECT table_name, column_name
FROM information_schema.columns
WHERE (column_name LIKE '%unit') AND (column_name Not LIKE '%base_unit%')
ORDER BY table_name

OPEN @CrsrVar

Fetch Next from @CrsrVar

While (@@Fetch_STATUS = 0)
set @sSQL = 'UPDATE' +

Fetch Next from @CrsrVar

END

What need to do is a dynamic update in the while statement where I can pull the table and column names and put in the where clause conditions and the value that the new value will be updated to. I have searched BOL and this site but I haven't quite seen anything that does this. Could you please point in the right direction? Thanks."

X002548
Not Just a Number

15586 Posts

Posted - 2006-11-17 : 10:50:50
Here's the searching component

http://weblogs.sqlteam.com/brettk/archive/2005/02/08/4144.aspx



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-11-18 : 04:57:20
Also refer
http://vyaskn.tripod.com/search_all_columns_in_all_tables.htm

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -