Hi All,
I hope this isn't a common question that you are sick of answering. I have a big table on an AS400 I am querying through Access using ODBC. The table is basically a parent-child structure, see below for an example:
PARENT CHILD CHILD-DESCRIPTION
U.S. South Carolina State
U.S. New York State
U.S. New Jersey State
South Carolina Columbia City
New York New York City City
South Carolina Charlestown City
Confederacy South Carolina State
Confederacy Alabama State
I need a query to produce a bill of materials for a given Parent that will go down N number of levels, until it hits the bottom. A child can have multiple parents, and parents can have multiple children.
A BOM for the U.S. from this table would look something like this:
Level Item Description
1 U.S.
2 South Carolina State
3 Columbia City
3 Charlestown City
2 New York State
3 New York City City
2 New Jersey State
So, what should I do? Try to hurt my head with recursion? Do a nested loop? I don't have a way to know the max "depth" of the BOM. Could be 5 or 6 levels, or more.
I am fairly new to Access and SQL, so if any of you gurus out there could help me out with the SQL, I sure would appreciate it.
I've been a lurker for some time, but this is my first time posting, so please be gentle.
Thanks,
Eric
I hope this isn't a common question that you are sick of answering. I have a big table on an AS400 I am querying through Access using ODBC. The table is basically a parent-child structure, see below for an example:
PARENT CHILD CHILD-DESCRIPTION
U.S. South Carolina State
U.S. New York State
U.S. New Jersey State
South Carolina Columbia City
New York New York City City
South Carolina Charlestown City
Confederacy South Carolina State
Confederacy Alabama State
I need a query to produce a bill of materials for a given Parent that will go down N number of levels, until it hits the bottom. A child can have multiple parents, and parents can have multiple children.
A BOM for the U.S. from this table would look something like this:
Level Item Description
1 U.S.
2 South Carolina State
3 Columbia City
3 Charlestown City
2 New York State
3 New York City City
2 New Jersey State
So, what should I do? Try to hurt my head with recursion? Do a nested loop? I don't have a way to know the max "depth" of the BOM. Could be 5 or 6 levels, or more.
I am fairly new to Access and SQL, so if any of you gurus out there could help me out with the SQL, I sure would appreciate it.
I've been a lurker for some time, but this is my first time posting, so please be gentle.
Thanks,
Eric