34,591
社区成员
发帖
与我相关
我的任务
分享
with tb(txt)
as(
select 'a\b\1.txt' union all
select 'a\b\2.txt' union all
select 'a\2.jpg' union all
select 'b\1\5.jpg')
,cte
as(
select
[all]=substring(t.txt+'\',1,number-1),
txt=(case when charindex('\',reverse(substring(t.txt+'\',1,number-1)))-1<0 then substring(t.txt+'\',1,number-1) else
right(substring(t.txt+'\',1,number-1),
charindex('\',reverse(substring(t.txt+'\',1,number-1)))-1)
end)
from tb t,master..spt_values where type='p' and number between 1 and len(t.txt)+1 and substring(t.txt+'\',number,1)='\'
)
select distinct txt,[all] from cte order by [all]