I need to create a resource tree / org chart.
I have a table
[tt]
Resources
---------------------------------------------------
ResID Name MgrID Layer TreeID
1 Bill 2
2 Paul 0
3 Mary 4
4 John 2
5 Thom 2
6 Carl 4
--------------------------------------------------
[/tt]
I need to populate the Layer and TreeID fields such that I can get this output
[tt]
---------------------------------------------------
ResID Name MgrID Layer TreeID
2 Paul 0 1 1
1 Bill 2 2 2
4 John 2 2 3
6 Carl 4 3 4
3 Mary 4 3 5
5 Thom 2 2 6
--------------------------------------------------
[/tt]
I am doing this in MS Access ADP and SQL Server 2000. I am pretty decent at Access MDBs but I am very new to ADPs, SQL Server 2000 and Transact-SQL.
In the MDB version of this database, I used a short bit of recursive code. It was slow, but it worked.
I could probably do this with cursors in a stored procedures but everyone says "cursors are bad" and I have a problem with the recursive call to an SP with cursors because cursors can't be reallocated until they are deallocated.
How else might I do this on the server side?
Thanks,
Jonathan
________________________________________
It is not fair to ask of others what you are unwilling to do yourself.
-Eleanor Roosevelt
I have a table
[tt]
Resources
---------------------------------------------------
ResID Name MgrID Layer TreeID
1 Bill 2
2 Paul 0
3 Mary 4
4 John 2
5 Thom 2
6 Carl 4
--------------------------------------------------
[/tt]
I need to populate the Layer and TreeID fields such that I can get this output
[tt]
---------------------------------------------------
ResID Name MgrID Layer TreeID
2 Paul 0 1 1
1 Bill 2 2 2
4 John 2 2 3
6 Carl 4 3 4
3 Mary 4 3 5
5 Thom 2 2 6
--------------------------------------------------
[/tt]
I am doing this in MS Access ADP and SQL Server 2000. I am pretty decent at Access MDBs but I am very new to ADPs, SQL Server 2000 and Transact-SQL.
In the MDB version of this database, I used a short bit of recursive code. It was slow, but it worked.
I could probably do this with cursors in a stored procedures but everyone says "cursors are bad" and I have a problem with the recursive call to an SP with cursors because cursors can't be reallocated until they are deallocated.
How else might I do this on the server side?
Thanks,
Jonathan
________________________________________
It is not fair to ask of others what you are unwilling to do yourself.
-Eleanor Roosevelt