camerontaylor
New member
- Local time
- Today, 14:10
- Joined
- May 11, 2021
- Messages
- 29
I downloaded a template parts tree database from the internet, just to try to get some intuition about how I might be able to create my own, or potentially modify the one that I downloaded. However, once I opened up the query, it completely goes over my head. I am hoping that someone can try to explain it to me in more layman terms, as I am still fairly new to SQL. I know the basics, but this is just beyond me.
Here is the SQL:
I have attached an image of the design view as well, as I find that that might help. Even if someone can explain what is happening in the first few cards on the left of the design view, it might be enough to trigger my understanding and allow me to understand how it works.
There is a table called Parts containing fields: PartNum, PartName, Cost, Category
There is a table called PartStructure containing fields: MajorPartNum, MinorPartNum, Quantity
Any help is appreciated, I just want to be able to understand the syntax and how everything is connected.
Here is the SQL:
Code:
SELECT P1.PartName AS Part, [P2].[PartName]+(" (" & [PS1].[Quantity] & ")") AS Component1, [P3].[PartName]+(" (" & [PS2].[Quantity] & ")") AS Component2, [P4].[PartName]+(" (" & [PS3].[Quantity] & ")") AS Component3, [P5].[PartName]+(" (" & [PS4].[Quantity] & ")") AS Component4, [P6].[PartName]+(" (" & [PS5].[Quantity] & ")") AS Component5, [P7].[PartName]+(" (" & [PS6].[Quantity] & ")") AS Component6, [P8].[PartName]+(" (" & [PS7].[Quantity] & ")") AS Component7, [P9].[PartName]+(" (" & [PS8].[Quantity] & ")") AS Component8, [P10].[PartName]+(" (" & [PS9].[Quantity] & ")") AS Component9, P1.PartNum
FROM Parts AS P1 LEFT JOIN (((((((((((((((((PartStructure AS PS1 LEFT JOIN PartStructure AS PS2 ON PS1.MinorPartNum = PS2.MajorPartNum) LEFT JOIN PartStructure AS PS3 ON PS2.MinorPartNum = PS3.MajorPartNum) LEFT JOIN PartStructure AS PS4 ON PS3.MinorPartNum = PS4.MajorPartNum) LEFT JOIN PartStructure AS PS5 ON PS4.MinorPartNum = PS5.MajorPartNum) LEFT JOIN PartStructure AS PS6 ON PS5.MinorPartNum = PS6.MajorPartNum) LEFT JOIN PartStructure AS PS7 ON PS6.MinorPartNum = PS7.MajorPartNum) LEFT JOIN PartStructure AS PS8 ON PS7.MinorPartNum = PS8.MajorPartNum) LEFT JOIN PartStructure AS PS9 ON PS8.MinorPartNum = PS9.MajorPartNum) LEFT JOIN Parts AS P2 ON PS1.MinorPartNum = P2.PartNum) LEFT JOIN Parts AS P3 ON PS2.MinorPartNum = P3.PartNum) LEFT JOIN Parts AS P4 ON PS3.MinorPartNum = P4.PartNum) LEFT JOIN Parts AS P5 ON PS4.MinorPartNum = P5.PartNum) LEFT JOIN Parts AS P6 ON PS5.MinorPartNum = P6.PartNum) LEFT JOIN Parts AS P7 ON PS6.MinorPartNum = P7.PartNum) LEFT JOIN Parts AS P8 ON PS7.MinorPartNum = P8.PartNum) LEFT JOIN Parts AS P9 ON PS8.MinorPartNum = P9.PartNum) LEFT JOIN Parts AS P10 ON PS9.MinorPartNum = P10.PartNum) ON P1.PartNum = PS1.MajorPartNum
WHERE (((P1.PartNum)=[Forms]![frmPartsTree]![lstParts])) OR ((([Forms]![frmPartsTree]![chkAllParts])=True));
I have attached an image of the design view as well, as I find that that might help. Even if someone can explain what is happening in the first few cards on the left of the design view, it might be enough to trigger my understanding and allow me to understand how it works.
There is a table called Parts containing fields: PartNum, PartName, Cost, Category
There is a table called PartStructure containing fields: MajorPartNum, MinorPartNum, Quantity
Any help is appreciated, I just want to be able to understand the syntax and how everything is connected.