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)
 Replace text in field that has other text

Author  Topic 

Gingerr
Starting Member

1 Post

Posted - 2012-04-21 : 18:53:11
I'd like to replace a four character string in a field in a 2005 sql table that has other information of varying lengths (so I can never pinpoint where the text I want to replace will be).

Let's say the text is GING and I want to replace with LIST everywhere it exists in the field. For example the field might have Archer Road GING 3980 Fairmont Circle.... in one record, Penople Street GING 6543 Main Street .... in another etc.

I see you can replace the whole field with a replace statement but can't find where you can replace text within the field, something like this

Update matters
set shortdesc = replace(select '%GING%', 'GING', 'PING')

This didn't work of course....

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-21 : 19:14:35
[code]
Update matters
set shortdesc = stuff(shortdesc,patindex('%GING%',shortdesc) ,4, 'PING')
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-04-21 : 19:15:14
Update matters
set shortdesc = replace(shortdesc, 'GING', 'PING')


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -