Solved

Find and Replace Data within a whole table

Posted on 2009-07-09
3
409 Views
Last Modified: 2012-06-27
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
Comment
Question by:N R
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 24818145
No,you have to write different statements for each of these columns
0
 
LVL 11

Author Closing Comment

by:N R
ID: 31601823
Well that sucks, ok thanks.
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24818232
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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MS SQL Bulk load data error 5 33
SQL Select Query help 3 31
SQL query 4 29
Left Join with Tuple returning more rows 10 41
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now