recursion - Recursive SQL for a menu system -


I have the following structure and some data for a menu system.

 id, text, parent id, destinations 1, application, (empty), (empty) 2, game, (empty), (empty) 3, office, 1, (empty) 4, text editing, 1, (empty) 5, media, (tap) 6, word, 3, 1 7, excel, 3, 2 8, cryisys, 2, 3 

What I need is a query in which I can pass, and it will return a list of items which have an ID as a child but, I need it to be returned only to such children. There is a valid path for the destination. In the above example, the user will be presented in the beginning (application, game), when he selects the applications, he will be presented with the (office). Text editing and media should be omitted because they do not have a valid destination.

The most difficult thing about this is that there is no predetermined depth in a given menu.

edit :

Today, the problem has come for MS SQL 2008, but in the last 2 weeks I have similar solutions for SQLite and SQL CE the wanted. The ideal solution should not be linked to any specific SQL engine.

Only SQL Server, but it seems like a job.


Comments