469,592 Members | 2,026 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

Search and replace on all columns

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;
Aug 17 '07 #1
0 1050

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Ryan | last post: by
22 posts views Thread by Phlip | last post: by
5 posts views Thread by pembed2003 | last post: by
32 posts views Thread by tshad | last post: by
2 posts views Thread by Michael Peters | last post: by
14 posts views Thread by Simon Gare | last post: by
6 posts views Thread by simon.robin.jackson | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.