![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I administer a mechanical engineering database. I need to build a query which uses the results from a subquery as its input or criterion. I am attempting to find all of the component parts of which a part may be composed. I have a table of parts and their subparts. The problem is that each of those subparts may be composed of smaller component parts. The subpart would then be listed in the Part field linked to each of its subparts in the Subpart field. I need to build a query which finds all of the subparts to the 4th degree. The query I built has had queer results, so I am doing something wrong. I failed to write an SQL statement that nests the subquery properly. When using the QueryBuilder and putting the subquery in the table field I get problems even before trying to link the result of the first query to another field. It displays the result of the first query once for each row of the table. When I run the subquery as its own query the result displays only once as expected. I have researched this in the Access 2002 bible and over the net without finding help. Suggestions? |
#3
| |||
| |||
|
|
I administer a mechanical engineering database. I need to build a query which uses the results from a subquery as its input or criterion. I am attempting to find all of the component parts of which a part may be composed. I have a table of parts and their subparts. The problem is that each of those subparts may be composed of smaller component parts. The subpart would then be listed in the Part field linked to each of its subparts in the Subpart field. I need to build a query which finds all of the subparts to the 4th degree. The query I built has had queer results, so I am doing something wrong. I failed to write an SQL statement that nests the subquery properly. When using the QueryBuilder and putting the subquery in the table field I get problems even before trying to link the result of the first query to another field. It displays the result of the first query once for each row of the table. When I run the subquery as its own query the result displays only once as expected. I have researched this in the Access 2002 bible and over the net without finding help. Suggestions? |
#4
| |||
| |||
|
|
I can help! If you would like my help, contact me at the email address below. |
#5
| |||
| |||
|
|
"K. Crothers" <k_crothers (AT) yahoo (DOT) com> wrote in message news:88684cf9.0405170948.4978def0 (AT) posting (DOT) google.com... I administer a mechanical engineering database. I need to build a query which uses the results from a subquery as its input or criterion. I am attempting to find all of the component parts of which a part may be composed. I have a table of parts and their subparts. The problem is that each of those subparts may be composed of smaller component parts. The subpart would then be listed in the Part field linked to each of its subparts in the Subpart field. I need to build a query which finds all of the subparts to the 4th degree. The query I built has had queer results, so I am doing something wrong. I failed to write an SQL statement that nests the subquery properly. When using the QueryBuilder and putting the subquery in the table field I get problems even before trying to link the result of the first query to another field. It displays the result of the first query once for each row of the table. When I run the subquery as its own query the result displays only once as expected. I have researched this in the Access 2002 bible and over the net without finding help. Suggestions? Post some information about your table structure(s) with some sample data and the output you need and we will help. |
#6
| |||
| |||
|
|
I have researched this in the Access 2002 bible and over the net without finding help. Suggestions? Post some information about your table structure(s) with some sample data and the output you need and we will help. SAMPLE DATA Child Part Table PartNumber ChildPart (keyID) 1000 1100 1000 1200 1000 1300 1100 1110 1100 1120 1200 1250 1200 1270 1250 1255 2000 2500 2000 2800 3000 3200 etc. (ChildParts do not follow this numbering convention.) Part Table PartNumber (keyID) 1000 1100 1110 1120 1200 1250 1255 1270 1300 2000 2500 2800 3000 3200 etc. Query Criterion: '1000' Query Output: 1100 1200 1300 1110 1120 1250 1270 1255 |
#7
| |||
| |||
|
|
"K. Crothers" <k_crothers (AT) yahoo (DOT) com> wrote in message news:88684cf9.0405171521.14195095 (AT) posting (DOT) google.com... I have researched this in the Access 2002 bible and over the net without finding help. Suggestions? Post some information about your table structure(s) with some sample data and the output you need and we will help. SAMPLE DATA Child Part Table PartNumber ChildPart (keyID) 1000 1100 1000 1200 1000 1300 1100 1110 1100 1120 1200 1250 1200 1270 1250 1255 2000 2500 2000 2800 3000 3200 etc. (ChildParts do not follow this numbering convention.) Part Table PartNumber (keyID) 1000 1100 1110 1120 1200 1250 1255 1270 1300 2000 2500 2800 3000 3200 etc. Query Criterion: '1000' Query Output: 1100 1200 1300 1110 1120 1250 1270 1255 If you know you will only ever have four levels you could do something like this. It's not pretty but it will work. parameters [partnum] int; select '' as hierarchy, PartNumber from Parts where PartNumber = [partnum] union all select '-', ChildPart from ChildParts where PartNumber = [partnum] union all select '--', c2.ChildPart from ChildParts c1 inner join ChildParts c2 on c1.ChildPart = c2.PartNumber where c1.PartNumber = [partnum] union all select '---', c3.ChildPart from ( ChildParts as c1 inner join ChildParts as c2 on c1.ChildPart = c2.PartNumber ) inner join ChildParts AS c3 on c2.ChildPart = c3.PartNumber where c1.PartNumber=[partnum] order by hierarchy, PartNumber There are better designs for hieracrchies - detaills of one at http://www.mvps.org/access/queries/qry0023.htm |
![]() |
| Thread Tools | |
| Display Modes | |
| |