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.
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 FILEPATHwhatever1 C:\folder9\folder1\APPLE\folder5whatever2 C:\folder8\folder7\APPLE\folder6whatever3 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 Kizeraka tduggan |
|
|
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). |
|
|
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 YourTableSET 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 Kizeraka tduggan |
|
|
slymonkey
Starting Member
5 Posts |
Posted - 2006-06-28 : 19:16:55
|
Thank you very much. Worked like a charm! |
|
|
|
|
|