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
 General SQL Server Forums
 New to SQL Server Programming
 Altering a substring

Author  Topic 

aberbotimue
Starting Member

26 Posts

Posted - 2009-09-15 : 19:09:47
Hi all..

I have the basics down, but this is beyond me..

I have too many to do by hand..

the bit of sql that displays them all, is

select url from buy_tb where url like '%dev%'

as you can see it will display all the urls with 'dev' in them

I want to then alter them all to have 'prod' where ever it says 'dev'

How easy is this to do..??

I am currently on an old version of sql server

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-09-15 : 19:55:51
You can use the REPLACE function when you perform the UPDATE:

UPDATE t1
SET Column1 = REPLACE(Column1, 'dev', 'prod')

You should probably not be storing (hard coding) dev/prod in your data, but rather handle this type of thing through a config file.

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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

aberbotimue
Starting Member

26 Posts

Posted - 2009-09-15 : 21:18:09
Worked like a dream.. Thankyou..

and the dev / prod example, was aiming to give an example folks would understand, explaining I wanted madeeasyco changed to madeeasy-20 was a harder one to understand why!!

But Thankyou for the advice! And thankyou for the SQL..
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-09-16 : 13:14:07
You're welcome.

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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -