I think this will work whether it is a TEXT or a VarChar column:
Main Topics
Browse All TopicsI have a SQL 2005 Express table that has a text column named 'memo'. I need a SQL query to select all rows where 'memo' contains 'msgsrv' and replace that with 'msgserver'. I know how to run a query in the Visual Management Studio. Any help would be appreciated. Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I appreciate all of the responses, but either:
1. The offered scripts did not work; or gave errors; or
2. I was unsure of whether the script would change my data without me being able to verify the changes first.
I also was not sure of some of the syntax. My table name was 'tm9user.template' is this supposed to be entered with single quotes, double quotes or [ ] brackets?
where I see '%' in Ralph Avery's script is that correct or do I put the text value I'm looking for there ie 'msgsrv'?
the field is a text field. Thanks again
I'm sorry. I gave you some bad code. Must have been sleepy.
The query to find the values would be....
select * from [table] where
Cast(memo as Varchar(Max)) like '%' + 'msgsrv' + '%'
You can even test to see what it will do with the results if you do... (NewValue will contain the value that the query will change the results to)
select * ,
--UPDATE t set
Memo = Replace(cast(memo as varchar(max)), 'msgsvr', 'msgserver')
From [table] t where
Cast(memo as Varchar(Max)) like '%' + 'msgsrv' + '%'
Then if you're satisfied with the results, you can remove the -- in front of the 'UPDATE' statement and run from that line down.
Note: mazher has a point about the problem that may result with the values being > 8000 characters. (4000 if it's unicode). You can add "And len(memo) > 7996 (since you're adding 3 characters to the overall length in the update.
If you're updating some critical data, I'd suggest copying the table and testing it on that first.
Business Accounts
Answer for Membership
by: aneeshattingalPosted on 2009-10-23 at 14:56:40ID: 25649084
is it a text column or a varchar(max) column