Solved

Replace a string

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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…

752 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