79254996

Date: 2024-12-05 14:06:56
Score: 1.5
Natty:
Report link

As per my understanding, you need a parent-child relationship,

Please check this query I prepared in SQL.

DECLARE @WorkingDirectory TABLE
(
    Id int IDENTITY(1,1),
    Name NVARCHAR(MAX),
    ParentId INT NULL
)

INSERT INTO @WorkingDirectory
VALUES('RootFolder',NULL),
('SubFolder1',1),
('SubFolder2 ',1),
('SubSubFolder1 ',2),
('RootFolder2',NULL),
('RootFolder1 ',5),
('SubFolder1 ',6),
('SubFolder2 ',6),
('SubSubFolder1',7)


;with subordinate as 
(
    select Id ,Name ,ParentId from @WorkingDirectory w  where ParentId IS NULL 
    union all
    select wd2.Id ,wd2.Name ,wd2.ParentId from @WorkingDirectory wd2  
    inner join subordinate s on s.Id= wd2.ParentId
)
select s.Id,s.Name,s.ParentId
from subordinate s
order by s.Id asc
OutPut

enter image description here

Do you want to get data based on the query? So you have to add a where condition in the CTE.

"copySourceFolderId": 1

--SQL QUERY
select s.Id,s.Name,s.ParentId
from subordinate s
WHERE (id = 1 OR ParentId=1)
order by s.Id asc
Reasons:
  • Blacklisted phrase (1): Please check this
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
Posted by: jishan siddique