Входные данные выглядят как
/nfs/site/disks/mtl_workdisk_003/mtlmedia/filter_bundle2846/regress/
/nfs/site/disks/mtl_workdisk_003/mtl3d/filter_bundle2846/regress/
/nfs/site/disks/mtl_workdisk_003/etl66/filter_bundle2846/regress/
Результат должен быть
mtlmedia
mtl3d
etl66
Я могу успешно получить результат, но есть ли способ упростить его с помощью других функций или методов?
declare @T table
(
InputString varchar(max)
);
insert into @T values
('/nfs/site/ssd/mtl_workdisk_1/mediatek/filter_candle46/regression/'),
('/nfs/location/disks/mtl_workdisk_003/mtl3d/filter_candle2846/regress/'),
('/nfs/place/disks/mtl_workdisk_003/etl1266/bundle2846/regress/') ;
select -- P1.Pos, P2.Pos, P3.Pos,P4.Pos,P5.Pos,P6.Pos,
substring(InputString, P5.Pos + 1, P6.Pos - P5.Pos - 1) as OutputString
from @T
cross apply (select (charindex('/', InputString))) as P1(Pos)
cross apply (select (charindex('/', InputString, P1.Pos+1))) as P2(Pos)
cross apply (select (charindex('/', InputString, P2.Pos+1))) as P3(Pos)
cross apply (select (charindex('/', InputString, P3.Pos+1))) as P4(Pos)
cross apply (select (charindex('/', InputString, P4.Pos+1))) as P5(Pos)
cross apply (select (charindex('/', InputString, P5.Pos+1))) as P6(Pos) ;