How can i display the name of the folder from a field in a table

How can i display the name of the folder from a field in a table.

Right now i have a field like this, which is a combination of path and file name: /folder/folder1/folder2/12345-ABCD.txt

I want to show this section into a new field in a table: /folder2/
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This is ugly but it works.  If the field is called folderfield:

reverse(substring(reverse(folderfield),charindex('/',reverse(folderfield)),      charindex('/',reverse(folderfield),charindex('/',reverse(folderfield))+1)  - charindex('/',reverse(folderfield))+1)) as foldername
FROM table

This reverses the path so the folder name is after the first '/' then it finds the second '/' in the reversed string and extracts it with substring, then it reverses it back.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GiftcardAuthor Commented:
Hammo, That Works. I found other way of solving this.

declare @q varchar(100)
declare @p varchar(100)

set @q = '/folder/folder1/folder2/12345-ABCD.txt'
set @p = substring( REVERSE(@q), charindex('/',REVERSE(@q))+1 , LEN(REVERSE(@q)))

select reverse(SUBSTRING( @p, 1, CHARINDEX('/', @p)-1))

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.