Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

La query ricorsiva SQL restituisce solo l'ultima riga

with recury as (
Select 
fs1.ID ,fs1.FParent,fs1.FName 
from  FoldersStructure as  fs1
where fs1.ID=8

union all
select fs2.id,fs2.FParent,fs2.FName 
from FoldersStructure as  fs2
inner join recury as r on fs2.ID= r.FParent

)
select ID,FParent,FName
from recury 
order by ID 

SQL-Fiddle