![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have a department table like this: DeptID Department ParentID, Lineage 1 HR NULL ( 2 Temp1 1 (1, 3 Temp2 2 (1,2 4 PC NULL ( I have a deptmember table like this: DeptID MemberID IsManager 1 1 Y 4 1 Y I need to query table to get all department belong to MemberID 1 with all children departments. My thought is: 1. Do Select * from deptmember where MemberID=1 and IsManager=Y 2. Loop thru this table to build SQL Where Lineage like '%1' OR Lineage like '%4' 3. Select * from department using where statement from step 2. How do you loop thru results from step1, Do I need to use a cursor? Thanks, HL |
#3
| |||
| |||
|
|
Final note: you might wish to google this group for "nested sets model", to see a different approach to storing hierarchies in an RDBMS that many people prefer. |
#4
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |