can''t get substring filename!

  • Does anyone know how to extract only the file name (resume.doc) from a string like this:

    C:\Documents and Settings\User1\Desktop\resume.doc 

    thanks for any assistance....

    kristin

     

     


    Kristin

  • declare @test-2 varchar(1000), @check int

    set @test-2 = 'C:\Documents and Settings\User1\Desktop\resume.doc'

    set @check = charindex('\', @test-2, 0)

    while @check <> 0

      begin

      set @test-2 = right(@test, len(@test) - @check)

       set @check = charindex('\', @test-2, 0)

      end

    select @test-2

  • Or, if you want to do it in one expression, it's easy if you reverse the string:

    REVERSE(SUBSTRING(REVERSE(@test),1,charindex('\',reverse(@test))-1))

     



    Mark

  • LOL...that would be easier.

  • yeah, that was easier, works perfect thank you so much


    Kristin

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply