August 19, 2010 at 12:04 pm
Hello Everyone
I am trying to write a backup process that spans domains. Unfortunately I cannot use Log Shipping due to the horrible network architecture.
I have the backup path from the backupset table, I would like to cut this down to the file name from the entire path name.
This is the path:
\\IP_Address\DirName\DirName\DirName\twProcessDB_20100819173001.trn
Each log file name will be the same length. Just as above. I would like to get the log file name only. I am close. But I cannot seem to get it.
Thanks in advance for your help
Andrew SQLDBA
August 19, 2010 at 12:30 pm
Perfect
Thank you
I did not think about using 'Reverse' that is what was holding me up, and mine was not working.
Thanks again
Andrew SQLDBA
August 19, 2010 at 12:58 pm
Yup, anything you need the last of something that's a really good way to go :hehe:.
August 19, 2010 at 3:14 pm
OK, how about the opposite:
I would like to keep the path and do away with the file name:
\\IP_Address\DirName\DirName\DirName\twProcessDB_20100819173001.trn
I would like to have this returned:
\\IP_Address\DirName\DirName\DirName
Thanks
Andrew SQLDBA
August 19, 2010 at 3:33 pm
Based on Ninja's_RGR'us code snippet:
SELECT LEFT(@str,LEN(@str)-CHARINDEX('\', REVERSE(@str), 1))
August 19, 2010 at 3:34 pm
@derrick: I didn't copy your code! Honestly! ;-):-D
August 19, 2010 at 3:36 pm
Hah 🙂
Actually ninja's code was very good...I've never really had a case where I needed to use reverse(), but now I bet I can find some. I had always just dealt with fixed length and a combination of left(right()) etc.
August 19, 2010 at 3:44 pm
Thanks Everyone
That code does the trick
I missed the last numeral 1
That was totally throwing me for a loop
Andrew SQLDBA
August 20, 2010 at 4:19 am
August 20, 2010 at 8:23 am
August 20, 2010 at 8:38 am
Yup... but only use in this case. When manipulating names and adresses you can get in trouble. But in this case the only trouble would be to have the folder name exactly the same as the filename. So for 99.999% of us it shouldn't be an issue :-P.
August 23, 2010 at 8:28 am
Hi, This will give you the file name alone
select right(@str,charindex('\',reverse(@str),0) - 1)
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply