Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to replace string in SQL

Author  Topic 

khufiamalik
Posting Yak Master

120 Posts

Posted - 2008-08-20 : 01:18:07
Hello All,
I have a string and want to replace a part of string with another

I know this can be done with the help of replace BUT
problem is that the string that i want to replace ,exists more than once , and I want to replace only first occurance of that string.

Like
'This Wolrd is a beautiful place for beautiful hearts'
and I just want to replace the 1st 'beautiful' with the word 'Good'

Waiting for your Kind reply
Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-20 : 01:26:34
use STUFF

select stuff('This Wolrd is a beautiful place for beautiful hearts',patindex('%beautiful%','This Wolrd is a beautiful place for beautiful hearts'),len('beautiful'),'Good')

in actual case replace strings with actual field and parameter names
Go to Top of Page
   

- Advertisement -