user3219693
user3219693

Reputation: 201

Find sub folder in a file path

Sorry I have searched and googled but I can't seem to find what I'm after;

I have a list of filepaths like below:

/ReportingFolder/SubjectFolder/ReportName

I need to get the SubjectFolder, what is the simplest way?

I have tried the below but that gives me the ReportingFolder:

LEFT((substring(Path, 2, (LEN(Path) - 1))), CHARINDEX('/', (substring(Path, 2,(LEN(Path) - 1)))) - 1) AS Folder

Upvotes: 0

Views: 320

Answers (1)

jpw
jpw

Reputation: 44921

This should work:

SUBSTRING (
    path,
    CHARINDEX('/',path,2)+1,
    CHARINDEX('/',path,CHARINDEX('/',path,2)+2)-CHARINDEX('/',path,2)-1
    )

Upvotes: 2

Related Questions