I have a column in my SQL Server table with file paths (with folders and subfolders)
For example:
/Hidden Reporting/Validation Report
/Top Reporting/Inner/TopTools Report
I currently have a query which returns all main folders of these path:
Select Distinct
LEFT((substring(Path, 2, (LEN(Path) - 1))), CHARINDEX('/', (substring(Path, 2,(LEN(Path) - 1)))) - 1) AS Folder
FROM dbo.Catalogs
Where Type=2
Result:
Hidden Reporting
Top Reporting
But I need to get subfolders too.
For example:
Hidden Reporting
Top Reporting
Inner
How can I do it in SQL Server 2008?
First create a table valued function to split the string. I got the below function to split from some where else
Now you can execute the select query below to get the desired output