I'm looking for a way to do a search and replace on *all* columns in a table (SQL Server 2005). I have a table with over 500 columns; some columns are text (nvarchar) some are INT or BIT.
I have not used cursors but I should be able to pick it up... In search the Web, I found various partial solutions and I think something like the below should work. I'm not sure about the syntax stuff... Any thoughts?
Thx
DECLARE Table_Cursor CURSOR FOR
SELECT SysColumns.Name
FROM SysObjects, SysColumns
WHERE SysObjects.Name = 'TABLE_NAME'
AND SysObjects.ID = SysColumns.ID
OPEN Table_Cursor;
FETCH NEXT FROM Table_Cursor;
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE TABLE_NAME
SET Table_Cursor("Name") = ''
WHERE Table_Curser("Name") IS NULL OR crs("Name") = '.'
END;
CLOSE Table_Cursor;
DEALLOCATE Table_Cursor;