I have a table with a list of folders that looks like this:
Path Size
C:\ParentFolder\A 123
C:\ParentFolder\A\B 442434
C:\ParentFolder\A\B\C 13413412
C:\ParentFolder\D 2422341234
C:\ParentFolder\D\E 3342
C:\ParentFolder\D\E\F 2
C:\ParentFolder\D\E\G 2
...
I’m looking for some combination of SUM, GROUP BY, and PATINDEX/LTRIM/SUBSTRING/etc. which would give me back this:
Path SumSize
C:\ParentFolder\A 13855969
C:\ParentFolder\D 2422344580
...
C:\ParentFolder is a known prefix, but A,D,etc. are variable folder names. Do I need to write a function to accomplish that or can I use some combination of string functions?
Starting with your testing set,
you’d first determine what folders you want to summarize. I do so here by loading them into a temp table:
From here it’s easy, using the like clause:
Complications may ensue if your folders contain reserved characters used by the
likeclause:% _ ] [and a few others.