Solved

Replace a string

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…

929 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

12 Experts available now in Live!

Get 1:1 Help Now