Solved

Replace a string

Posted on 2009-06-29
4
308 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
  • 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 125 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

16 Experts available now in Live!

Get 1:1 Help Now