我有一个递归 CTE 查询,它从名为 HP Quality Center 的应用程序中的文件夹结构构造文件路径 - 我要做的只是根据符号“\”将字符串解构为特定文件夹长度.
可以解释一下这对于实际上并不“存在”的行是否可能可以这么说,即当我尝试使用 substring 和 charindex 函数时,查询生成器回来说列名是空白的。
非常感谢
with cycle_path (cf_item_id, cf_item_name, cf_path)
as
(
-- set up base
select 0, CONVERT(varchar(255),'Root'), CONVERT(varchar(255),'Root')
union all
-- determine path recursively
select cf.cf_item_id, cf.cf_item_name, CONVERT(varchar(255), cp.cf_path + '\' + cf.cf_item_name)
from cycl_fold cf
inner join cycle_path cp on cf.cf_father_id = cp.cf_item_id
)
select SUBSTRING(cp.cf_path, 0, CHARINDEX('\', cp.cf_path, CHARINDEX('\', cp.cf_path, CHARINDEX('\', cp.cf_path, CHARINDEX('\', cp.cf_path, 0) + 1) + 1) + 1)), cp.cf_path
from cycle_path cp
inner join cycle cy on cp.cf_item_id = cy.cy_folder_id
where cp.cf_path LIKE 'Root\%'
order by cp.cf_path