I have a recursive CTE query that constructs a file path from from a folder structure within an application called HP Quality Center - what I'm trying to do is simply de-construct the string to a certain folder length based upon a symbol '\'.
Could some explain as to whether this is possible with rows that doesn't actually 'exist' so to speak, i.e. as the query builder comes back saying that the column name is blank when I try to use the substring and charindex functions.
Many Thanks
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