Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2003
    Location
    In your thoughts
    Posts
    195

    Unanswered: 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, Jeremy
    Nothing better than a good ride.

  2. #2
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578
    Better to store PATH & FILENAME in seperate variables.

    Refer to this link for XP_FILEEXISTS which searches for the specified file, where you can use it for your task.

    HTH
    --Satya SKJ
    Microsoft SQL Server MVP
    [IMG]http://sqlserver-qa.net/google_bart.gif[/IMG]

  3. #3
    Join Date
    Apr 2003
    Location
    Israel
    Posts
    81
    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))
    --
    kukuk

  4. #4
    Join Date
    Aug 2002
    Location
    Scotland
    Posts
    1,578
    Valid tip Kukuk, keep it up.
    --Satya SKJ
    Microsoft SQL Server MVP
    [IMG]http://sqlserver-qa.net/google_bart.gif[/IMG]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •