I am trying to get the simple SQL Server 2008 Recursive Query to work.
Following these examples: http://msdn.microsoft.com/en-us/library/ms186243.aspx and SQL Server recursive query
I have a table, with id and parentID:
ID fParent fName
2 NULL root
3 2 Drug_Error
4 2 Incident
5 4 2007
6 4 2009
7 5 2007-1
8 7 2008-2
with the following query
with recury as (
Select
fs1.ID ,fs1.FParent,fs1.FName
from FoldersStructure as fs1
where fs1.FParent =null
union all
select fs2.id,fs2.FParent,fs2.FName
from FoldersStructure as fs2
inner join recury as r on fs2.FParent= r.ID
)
select ID,FParent,FName
from recury
where ID=8
I was hoping to get:
2 null root
4 2 incident
5 4 2007
7 5 2007-1
8 7 2007-2
But I only get the last one. thanks in advance.