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
 General SQL Server Forums
 New to SQL Server Programming
 Need a hierarchy query to form organization struct

Author  Topic 

btechrames
Starting Member

3 Posts

Posted - 2014-06-08 : 10:53:33

hi friends,

I need to write a sql that generate the hierarchy in an organization.
Below an example
emplid empname supervisor_id superv_name
1 subu null null
2 vid 1 sub
3 ram 4 satis
4 satis 2 vid

i need an output to this query as below and also one important the supervisor ie supervisor_id and name is null is the top level,every employee also has to report to him and also to his all above supervisors.

whoever joinng new to org the hierachy should be follwed

empid empname supervisor_id superv_name
3 ram 4 satis
4 satis 2 vid
2 vid 1 subu
4 satis 1 subu
3 ram 1 subu
3 ram 2 vid
5 kumar 1 subu
5 kumar 4 satis
5 kumar 2 vid
1 subu null null


Thanks n advance...

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2014-06-08 : 15:23:36
Duplicate of [url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=194593[/url]
Go to Top of Page
   

- Advertisement -