Stammbaum SQL-Abfrage
Ich arbeite an Family Tree-Anwendung in asp.net mit SQL Server 2008.
Mein Haupttisch sieht so aus: -
ID int PK
Name Varchar(50)
MotherID int
FatherID int
ID MotherID FatherID Name
1 NULL NULL My Grand Father
2 NULL NULL My Grand Mother
3 someid someid My Mother
4 2 1 My Father
5 3 4 Me
6 someid someid My wife
7 3 4 My Brother
8 6 5 My son.
Ich suche nach einer Ausgabe wie dieser
ID MotherID FatherID Name Level
1 someid someid grandfather 0
2 someid someid Father 1
3 someid someid Me 2
4 someid someid Brother 2
5 someid someid My Son 3
Danke im Voraus. Kaschmir.