Subject | Revursive Stored Procedure |
---|---|
Author | James N Hitz |
Post date | 2007-06-11T09:20:38Z |
Supposing I had a list of Departments in a table like this:
ID | DEPARTMENT | PARENTID
1 | INFO. TECH. | NULL
2 | ACCOUNTS | NULL
3 | SOFTWARE DEVLPT | 1
4 | REQUISITIONS | 2
14 | QUALITY ASSURANCE | 3
What would be the best way to produce output showing the entire path for
every "sub-department" (WHERE PARENTID NOT IS NULL ORDER BY 2) to get
something like this:
ID | DEPT_PATH
4 | ACCOUNTS - REQUISITIONS
3 | INFO. TECH. - SOFTWARE DEVLPT
14 | INFO. TECH. - SOFTWARE DEVLPT - QUALITY ASSURANCE
I think a recursive Stored Proc. Any suggestions?
Thanks
James
ID | DEPARTMENT | PARENTID
1 | INFO. TECH. | NULL
2 | ACCOUNTS | NULL
3 | SOFTWARE DEVLPT | 1
4 | REQUISITIONS | 2
14 | QUALITY ASSURANCE | 3
What would be the best way to produce output showing the entire path for
every "sub-department" (WHERE PARENTID NOT IS NULL ORDER BY 2) to get
something like this:
ID | DEPT_PATH
4 | ACCOUNTS - REQUISITIONS
3 | INFO. TECH. - SOFTWARE DEVLPT
14 | INFO. TECH. - SOFTWARE DEVLPT - QUALITY ASSURANCE
I think a recursive Stored Proc. Any suggestions?
Thanks
James