Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 File Paths stored in SQL
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 01/24/2013 :  09:53:18  Show Profile  Reply with Quote
Have an annoying problem in a table that stores metadata to files stored elsewhere. The file paths are stored every which way including local paths and UNCs. To add insult to injury the application seems to use back and front slashes interchangeably so a path could look like "c:\\Dir1/Dir2//Dir3\filename.txt" Typically, I wouldn't worry too much about this but I need ability to re-map any given path. So the code would take old Path and New path as parameters and will have to change any record in the table from old path to the new. So in this example input parameters might be "c:\Dir1", "\\Server\Share" Now I need to find every permutation of "c:\Dir1" in the table including "c:\Dir1", "c:\\Dir1", "c:/Dir1", "c://Dir1", etc...

Any ideas?

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 01/24/2013 :  13:07:36  Show Profile  Reply with Quote
If the variations are known, you should be able to use two (or more) nested replaces to get it to your desired format - for example like shown below
-- see if the path exists and what the fixed up path would be
SELECT dirpath, replace(replace(dirpath,'/','\'),'\\','\') FROM theTable;

-- replace with the new path
declare @newPath varchar(255)='D:\Dir1';
declare @oldPath varchar(255)='C:\Dir1';
	dirpath = @newPath
	replace(replace(dirpath,'/','\'),'\\','\')  = @oldPath ;
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000