• raym85 (3/25/2013)


    It bothered me now.

    So i had to come up with a way to, but I would prolly choose the first one opver my own.

    DECLARE @LastValue varchar(100)

    declare @string varchar (100)

    set @string = 'x:\folder1\folder2\folder3\test.txt'

    SET @LastValue = ( CHARINDEX('\', REVERSE(@string)))

    select SUBSTRING(@string,1, (LEN(@STRING) - CONVERT(INT,@LastValue))+1)

    This actually is pretty good. With a little modification you can remove the extra variable.

    select SUBSTRING(@string,1, LEN(@STRING) - CHARINDEX('\', REVERSE(@string)) +1)

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/