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 2000 Forums
 SQL Server Development (2000)
 Is it possible to replace the first occurrence of a string in a column ?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-06-07 : 08:19:31
Franck writes "Hello

When I read your article Using REPLACE in an UPDATE statement

I thought : That's exactly what I need...

After a closer look, it seems it's not exactly true...


REPLACE(string1,string2,string3) replaces all occurences of string2 by string3 in string1 and what I need to do is replace the first occurence and only the first one...

is there a way to do this ?

Please, say yes...

I'm running SQL Server 2000 SP2 on Windows 2000 SP2.


Thanks a lot"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-06-07 : 08:33:51
DECLARE @find varchar(8000)
SELECT @find='Replace this'
UPDATE myTable
SET myCol=Stuff(myCol, CharIndex(@find, myCol), Len(@find), 'Replacement text')


Go to Top of Page
   

- Advertisement -