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)
 Selective Replacement

Author  Topic 

slymonkey
Starting Member

5 Posts

Posted - 2006-06-28 : 18:08:59
I have a whole mess of filepaths I need to change in a field, but I only want to change the APPLE folder name in the below example. I am a newbie to SQL so I have no idea where to begin. Any help would be appreciated.

FILENAME    FILEPATH

whatever1    C:\folder9\folder1\APPLE\folder5
whatever2    C:\folder8\folder7\APPLE\folder6
whatever3    C:\folder3\folder2\APPLE\folder4

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-06-28 : 18:42:09
You can use the REPLACDE function.

Here is an example:

DECLARE @s varchar(50)
SET @s = 'C:\folder9\folder1\APPLE\folder5'
SELECT REPLACE(@s, 'APPLE', 'SomeNewFolder')

Tara Kizer
aka tduggan
Go to Top of Page

slymonkey
Starting Member

5 Posts

Posted - 2006-06-28 : 18:57:44
Thank you, that is a good start but my paths are different from each other. The only similarity is that they have the APPLE subfolder in them. How can I parse each cell in the FILEPATH field for APPLE and replace just that part of the string. Basically I need the replace to not be specific to a single path (if that makes sense).
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-06-28 : 19:02:47
If you want to update your data, then it's like this:

UPDATE YourTable
SET FILEPATH = REPLACE(FILEPATH, 'APPLE', 'WhateverTheNewNameIs')

So you just use FILEPATH instead of @s. @s was just used to show you an example. You then apply it to your situation.

Tara Kizer
aka tduggan
Go to Top of Page

slymonkey
Starting Member

5 Posts

Posted - 2006-06-28 : 19:16:55
Thank you very much. Worked like a charm!
Go to Top of Page
   

- Advertisement -