Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

What is the SQL syntax to find last directory name from a file path. For example I want to fetch the name of the last Directory i.e. C

Input:

/Directory_A/Directory_B/Directory_C/Folder1/Folder2

Output:

C
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
186 views
Welcome To Ask or Share your Answers For Others

1 Answer

DECLARE @path VARCHAR(100)='/Directory_A/Directory_B/Directory_C/Folder1/Folder2'

SELECT SUBSTRING( @path,LEN(@path)-LEN(SUBSTRING(@path,PATINDEX('%folder%',@path), 100))-1, 1)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...