SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

boblotz2001
Starting Member

USA
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

3742 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';
UPDATE theTable SET
	dirpath = @newPath
where
	replace(replace(dirpath,'/','\'),'\\','\')  = @oldPath ;
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000