UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Tree Structure Query, Office 2010    
 
   
karimibrahim
post Apr 3 2012, 10:35 AM
Post #1

New Member
Posts: 4



Hi
I have a table with two columns: Parent_ID and Child_ID
I want to create a query that will expand the tree structure of these relationship. How do I know the depth or how many levels a given Parent_ID will have?
One of my objectives is to obsolete some parents with their children (providing that the children are not part of any other parent's tree structure)

Thanks,
Karim
Go to the top of the page
 
+
ScottGem
post Apr 3 2012, 10:40 AM
Post #2

UtterAccess VIP / UA Clown
Posts: 25,021
From: LI, NY



What do you mean by Levels? Do you mean ChildIDs that might also be ParentIDs? Or do you mean how many ChildIDs to a ParentID? If the latter, just do a Group By query, Grouping on ParentID and COUNTing ChildIDs.
Go to the top of the page
 
+
karimibrahim
post Apr 3 2012, 10:51 AM
Post #3

New Member
Posts: 4



It is not as simple as a group by query
Some children will also be parents and if I want to see a complete structure end to end
So the level or depth means how many parts are involved in one structure. See example below:

Part_1
Part_2
Part_3
Part_4
Part_5

The depth or levels here are 4 an the table will look like this
Parent_ID Child_ID
Part_1 Part_2
Part_2 Part_3
Part_3 Part_4
Part_3 Part_5

What I want is to create a table like this:

Parent_ID Child_ID Depth (level)
Part_1 Part_2 1
Part_2 Part_3 2
Part_3 Part_4 3
Part_3 Part_5 3

How can I create a query that calculates the level and goes through thousands of records?

Go to the top of the page
 
+
thegeek
post Apr 3 2012, 01:35 PM
Post #4

UtterAccess Enthusiast
Posts: 67
From: chained to desk



It sounds like you need a recursive query but I don't believe you can do recursive queries in Access.

If your data resides in some other RDBMS that supports recursive queries you might be better off using a pass-through query to the other RDBMS.
Go to the top of the page
 
+
orange999
post Apr 3 2012, 01:50 PM
Post #5

UtterAccess Guru
Posts: 621
From: Ottawa, Ontario, Canada



see the comments at this site re recursive function call in vba/access
http://stackoverflow.com/questions/763016/...query-in-access
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 20th May 2013 - 07:02 AM