родословная sql запрос
Я работаю над приложением Семейное древо в asp.net с SQL Server 2008.
Мой основной стол выглядит так:
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.
Я ищу такой вывод
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
Заранее спасибо. Кашмир.