Skip to main content
added 231 characters in body
Source Link
Gerrit
  • 15
  • 1
  • 5

Found a Solution, although I am not sure, this is the best way to do it, but certainly sure, this is not the prettiest way to do it.

select x1.value as MainFolder, x2.value as SubFolder, x3.value as [secondSubFolder]
from Files f 
cross apply (
select xx.value, ROW_NUMBER() OVER (Partition by f.ParentPath order by f.ParentPath) AS PP
from string_split (f.ParentPath,'\') as xx
) as x1
cross apply (
select xx2.value, ROW_NUMBER() OVER (Partition by f.ParentPath order by f.ParentPath) as PP2
from string_split (f.ParentPath,'\') as xx2
) as x2
cross apply (
select xx3.value, ROW_NUMBER() OVER (Partition by f.ParentPath order by f.ParentPath) as PP3
from string_split (f.ParentPath,'\') as xx3
) as x3
where PP = 1
and PP2 = 2
and pp3 = 3
group by x1.value, x2.value, x3.value
order by MainFolder asc, SubFolder asc

is giving me : enter image description here

I left out the Size, as I was interested in dividing the Path into seperate folders first.

Edit: Sorry, this Screenshot is different to the question, due to sorting the results. To clarify: ParentPath to the displayed result would be: "Business Intelligence\GLS Paketdaten \ GLS Daten Archiv"

Or as a Table with posted content:

MainFolder      |  SubFolder   |  secondSubfolder
Business        |   Packets    |      Data 

P.S Sorry, English is not my first language. I hope I wrote it understandable.

Found a Solution, although I am not sure, this is the best way to do it, but certainly sure, this is not the prettiest way to do it.

select x1.value as MainFolder, x2.value as SubFolder, x3.value as [secondSubFolder]
from Files f 
cross apply (
select xx.value, ROW_NUMBER() OVER (Partition by f.ParentPath order by f.ParentPath) AS PP
from string_split (f.ParentPath,'\') as xx
) as x1
cross apply (
select xx2.value, ROW_NUMBER() OVER (Partition by f.ParentPath order by f.ParentPath) as PP2
from string_split (f.ParentPath,'\') as xx2
) as x2
cross apply (
select xx3.value, ROW_NUMBER() OVER (Partition by f.ParentPath order by f.ParentPath) as PP3
from string_split (f.ParentPath,'\') as xx3
) as x3
where PP = 1
and PP2 = 2
and pp3 = 3
group by x1.value, x2.value, x3.value
order by MainFolder asc, SubFolder asc

is giving me : enter image description here

I left out the Size, as I was interested in dividing the Path into seperate folders first.

Edit: Sorry, this Screenshot is different to the question, due to sorting the results. To clarify: ParentPath to the displayed result would be: "Business Intelligence\GLS Paketdaten \ GLS Daten Archiv"

Found a Solution, although I am not sure, this is the best way to do it, but certainly sure, this is not the prettiest way to do it.

select x1.value as MainFolder, x2.value as SubFolder, x3.value as [secondSubFolder]
from Files f 
cross apply (
select xx.value, ROW_NUMBER() OVER (Partition by f.ParentPath order by f.ParentPath) AS PP
from string_split (f.ParentPath,'\') as xx
) as x1
cross apply (
select xx2.value, ROW_NUMBER() OVER (Partition by f.ParentPath order by f.ParentPath) as PP2
from string_split (f.ParentPath,'\') as xx2
) as x2
cross apply (
select xx3.value, ROW_NUMBER() OVER (Partition by f.ParentPath order by f.ParentPath) as PP3
from string_split (f.ParentPath,'\') as xx3
) as x3
where PP = 1
and PP2 = 2
and pp3 = 3
group by x1.value, x2.value, x3.value
order by MainFolder asc, SubFolder asc

is giving me : enter image description here

I left out the Size, as I was interested in dividing the Path into seperate folders first.

Edit: Sorry, this Screenshot is different to the question, due to sorting the results. To clarify: ParentPath to the displayed result would be: "Business Intelligence\GLS Paketdaten \ GLS Daten Archiv"

Or as a Table with posted content:

MainFolder      |  SubFolder   |  secondSubfolder
Business        |   Packets    |      Data 

P.S Sorry, English is not my first language. I hope I wrote it understandable.

Source Link
Gerrit
  • 15
  • 1
  • 5

Found a Solution, although I am not sure, this is the best way to do it, but certainly sure, this is not the prettiest way to do it.

select x1.value as MainFolder, x2.value as SubFolder, x3.value as [secondSubFolder]
from Files f 
cross apply (
select xx.value, ROW_NUMBER() OVER (Partition by f.ParentPath order by f.ParentPath) AS PP
from string_split (f.ParentPath,'\') as xx
) as x1
cross apply (
select xx2.value, ROW_NUMBER() OVER (Partition by f.ParentPath order by f.ParentPath) as PP2
from string_split (f.ParentPath,'\') as xx2
) as x2
cross apply (
select xx3.value, ROW_NUMBER() OVER (Partition by f.ParentPath order by f.ParentPath) as PP3
from string_split (f.ParentPath,'\') as xx3
) as x3
where PP = 1
and PP2 = 2
and pp3 = 3
group by x1.value, x2.value, x3.value
order by MainFolder asc, SubFolder asc

is giving me : enter image description here

I left out the Size, as I was interested in dividing the Path into seperate folders first.

Edit: Sorry, this Screenshot is different to the question, due to sorting the results. To clarify: ParentPath to the displayed result would be: "Business Intelligence\GLS Paketdaten \ GLS Daten Archiv"