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
 Transact-SQL (2000)
 Update a Field

Author  Topic 

mlmeyer
Starting Member

26 Posts

Posted - 2005-05-16 : 16:47:06
Quick question on updating fields in a table. I just need to update all the URLs in a SQL database field so they include a new folder root. So, for example, I need to change this URL

http://www.website.com/images/image1.gif

to

http://www.website.com/images/home/images1.gif

In other words I just need to add the /home directory to all of the URLs in an image field of a table without changing anything else. I am sure there is an easy way to do this but I can't seem to find it.

CactusJuice
Starting Member

46 Posts

Posted - 2005-05-16 : 23:20:30
[code]SELECT STUFF('http://www.website.com/images/image1.gif', 30, 0, 'home')[/code]

Note, this is a very simplified example (I used fixed 30 for start location). Use PATINDEX or CHARINDEX to get this.

Check out BOL for the string functions.
Go to Top of Page

AndyB13
Aged Yak Warrior

583 Posts

Posted - 2005-05-17 : 01:43:53
Or you could use REPLACE

SELECT REPLACE('http://www.website.com/images/image1.gif','/images/','/images/home/')

Andy

Beauty is in the eyes of the beerholder
Go to Top of Page
   

- Advertisement -