Sunday, February 19, 2012

Get only a certain piece of a string

I have a table that holds file paths for reports. Let's say it looks like this:

C:\Jeremy\Testing\JCScoobyRS\Testing.txt

Let's assume that none of the files are in the same directory and the directory is not known, as I'm running a report to get only file names. How can I get only file names from the string listed above? Thanks, JeremyBetter to store PATH & FILENAME in seperate variables.

Refer to this link (http://www.nigelrivett.net/CheckIfFileExists.html) for XP_FILEEXISTS which searches for the specified file, where you can use it for your task.

HTH|||That's my (lazy) way to do it:

declare @.FP varchar(255)
select @.FP='C:\Jeremy\Testing\JCScoobyRS\Testing.txt'
select reverse(substring(reverse(@.FP),1,charindex('\',rev erse(@.FP))-1))|||Valid tip Kukuk, keep it up.

No comments:

Post a Comment