Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Replace a string

Posted on 2009-06-29
4
Medium Priority
?
315 Views
Last Modified: 2012-05-07
I have to update a table with the replace function. The table test has a column text.
This column has string 'Invalid ISBN {11111,222,333}'. I have to replace the string in { and } braces with the new variable value.
update test
set text = 'Invalid ISBN { ' + @ISBNlist + ' }'
where !ID = @id.
 
Can anyone tell me how to use replace in the above update statement?
 
Thanks,
-B

Open in new window

0
Comment
Question by:BrookK
[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
4 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24738923
if it is of the same struture you can overwrite the field

update test
set text = 'Invalid ISBN { ' + @ISBNlist + ' }'
where ID = @id
0
 
LVL 17

Accepted Solution

by:
pssandhu earned 375 total points
ID: 24739502
With Aneesh's suggestion it will much easier to achieve your task. However, here is an alternative if you are looking for one:
P.

DECLARE @t varchar(50), @StuffWith varchar(50)
 
SET @t = 'Invalid ISBN {11111,222,333}'
SET @StuffWith = '8547489+405616846'
 
Select STUFF(@t,PATINDEX('%_{%', @t)+2,LEN(@t)-(PATINDEX('%_{%', @t)+2), @StuffWith)

Open in new window

0
 

Author Comment

by:BrookK
ID: 24749010
Thanks guys. I implemented Aneesh's suggestion but Pssandhu's suggestion worked well too.

-B
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24750038
.......and you accepted the other solution
:)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 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