Solved

Replace a string

Posted on 2009-06-29
4
311 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…

821 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