Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 419
  • Last Modified:

Find and Replace Data within a whole table

I'm trying to update a entire table.  I don't just want to update one column but any of them that contain a character.  Is there a way to do one on all the columns rather than a separate statement for each column?
0
Nathan Riley
Asked:
Nathan Riley
  • 2
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
No,you have to write different statements for each of these columns
0
 
Nathan RileyFounderAuthor Commented:
Well that sucks, ok thanks.
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
you can generate the statements like this , run the query, copy -paste the results in a new query window

SELECT 'UPDATE  '+TABLE_NAME +' SET  '+ COLUMN_NAME +'  = REPLACE  ( '+COLUMN_NAME+', ''abc'', ''cde'' ) '
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'PutTableNameHere' AND DATA_TYPE IN ('Varchar', 'nvarchar', 'char','nchar')
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now