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
 Transact-SQL (2000)
 Hierarchy

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2004-06-24 : 12:09:31
I have two tables: organization and Organization_Relationship

Organization table has a unique Org_id

Org_id Org_name Org_address
100729
100731
100732
100733
100734
100735
100759
100761
100762
100730
100760


Organization relationship table shows the relationship between Org_id and it’s hierarchy.

Orginization relationship
Org_id Org_rel
100729 100730
100729 100731
100729 100735
100729 100759
100731 100732
100731 100733
100731 100734
100735 100736
100759 100760

There is a foreign key ( Org_id) relationship between two tables.

I would like to return the result that looks like:

Parent_org	Sub_org1	    Sub-org2
100729 100729 100729
100729 100730 100730
100729 100731 100731
100729 100731 100732
100729 100731 100733
100729 100731 100734
100729 100735 100736
100729 100759 100760


The logic here is:
1)Org_id 100729 itself can be both sub_org1 and sub_org2 because it’s a parent location (location level 1).
2)Org_id 100729 has 100730,100731,100735 and 100759 as Sub_org1
3)Org_id 100731 has 100732,100733 and 100734 as Sub_org2
4)Org_id 100735 is a child_location of 100729(parent_location) and parent_location of 100736(Sub_org2)





tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-06-24 : 12:30:49
Please post DDL and DML. CREATE TABLE and INSERT INTO (for sample data) statements.

Tara
Go to Top of Page
   

- Advertisement -