with temp AS (SELECT * FROM Report_Structure WHERE StructureID = 'F3A6A4A6-A3EE-4595-8EEF-C230416AE183' UNION ALL SELECT a.* FROM Report_Structure a INNER JOIN temp b ON a.ParentID = b.StructureID) SELECT * FROM temp
with temp AS (SELECT * FROM Report_Structure WHERE StructureID = 'F3A6A4A6-A3EE-4595-8EEF-C230416AE183' UNION ALL SELECT a.* FROM Report_Structure a INNER JOIN temp b ON a.ParentID = b.StructureID) SELECT * FROM temp