Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 A More involved Recursive search

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-11-02 : 08:12:48
Andrew writes "I have a few query questions.. if you have a table with the following definition:

Table
ID ParentID
1 NULL
2 1
3 2
4 3
5 NULL
6 NULL
7 5
8 7


if someone requests ID 4 it should return rows:

4
3
2
1
(everything below it)

so 2 would return
1


if request was 8

8
7
5

if request was 6

6

not only that but going forward would be ideal as well. Should be achievable by doing the reverse on the parentID column.
if request was 2

3
4

if request was 7

8

oh and in SQL 2000 :) not 2005 :)"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-02 : 08:15:13
Refer these tree structures
http://www.nigelrivett.net/RetrieveTreeHierarchy.html
http://www.seventhnight.com/treestructs.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rfrancisco
Yak Posting Veteran

95 Posts

Posted - 2005-11-02 : 15:31:40
You may also look into these links:

http://www.sql-server-helper.com/functions/get-tree-path.aspx
http://www.sql-server-helper.com/functions/get-tree-node-level.aspx
Go to Top of Page
   

- Advertisement -