?
Solved

Find and Replace Data within a whole table

Posted on 2009-07-09
3
Medium Priority
?
415 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:Nathan Riley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 75

Accepted Solution

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

Author Closing Comment

by:Nathan Riley
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

765 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