T-SQL hierarchy - get breadcrumbs using query
问题 I have virtual folder structure saved in database and I want to get the breadcrumbs from the current folder to the root. The data can be unsorted (but better will be sorted) and I want the parent folders of the current folder only. The table definition is: DECLARE Folders TABLE ( FOL_PK INT IDENTITY(1,1) NOT NULL, FOL_Name VARCHAR(200) NOT NULL, FOL_FOL_FK INT NULL -- Foreign key to parent ) And this is my solution: DECLARE @FOL_PK INT = 5 -- Current folder PK DECLARE @breadcrumbs TABLE ( FOL