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)
 Tree Structure

Author  Topic 

josephmp
Starting Member

3 Posts

Posted - 2008-06-09 : 07:55:13
I have a table with EmployCode(int), EmployName(varchar) and SeniorCode(int).
The table maintains a tree like hierarchy with top most member having a senior code as 0 and all other members will have a valid EmployCode as the Senior Code. I want to display all the employs that comes above the given employ in the tree structue upto the top most member who have the senior code as 0. If i input an employ code it should return all the seniors of this employ present in the hierarchy.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-09 : 08:32:14
Search for expanding hierarchies in books online
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-09 : 08:34:52
Refer this too:-

http://www.sqljunkies.ddj.com/Article/D7CAED46-CCAC-4FF7-B528-B2E9A274B71C.scuk
Go to Top of Page

josephmp
Starting Member

3 Posts

Posted - 2008-06-09 : 09:20:47
Can i find the result without using the while loop. A recursive select statement or so.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-09 : 14:24:30
quote:
Originally posted by josephmp

Can i find the result without using the while loop. A recursive select statement or so.


You could do it with recursive CTE if you were using SQL 2005 or higher.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-09 : 15:29:00
quote:
Originally posted by josephmp

Can i find the result without using the while loop. A recursive select statement or so.


Why? I think in SQL Server 2000 it is not possible without using while loop

Madhivanan

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

josephmp
Starting Member

3 Posts

Posted - 2008-06-10 : 05:10:08
I have around 20000+ employees and I need to find the list of users senior to each of these users so as to split some amount between them. This operation has to be done often and the user hierarchy may vary each time. I need a method to generate this list with less time. Can u suggest a method in SQL 2000; also can you please tell me how to solve this in SQL 2005.
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2008-06-13 : 23:15:57
Here is some info for a Sql Server 2000 implementation...

http://www.seventhnight.com/treeStructs.asp
http://www.seventhnight.com/treeStructs2.asp
http://www.seventhnight.com/treeStructs3.asp

Corey

snSQL on previous signature "...Oh and by the way Seventhnight, your signature is so wrong! On so many levels, morally, gramatically and there is a typo!"
Go to Top of Page
   

- Advertisement -