2.9 KiB
SP Product Data
Analysis generated on: 4/2/2025 10:12:10 AM
SQL Statement
SELECT [SP Product Entry].Obsolete, [SP Product Entry].ProductID, [SP Product Entry].PartsPerUnit, Process.*, [SP Units].UnitsPerYear, [ActualWt]*[PartsPerUnit]*[UnitsPerYear] AS [AW/Year], [GrossWt]*[PartsPerUnit]*[UnitsPerYear] AS [GW/Year]
FROM (Process INNER JOIN [SP Product Entry] ON Process.PartNumber = [SP Product Entry].PartNumber) LEFT JOIN [SP Units] ON [SP Product Entry].ProductID = [SP Units].ProductID
WHERE ((([SP Product Entry].Obsolete)=0))
ORDER BY [SP Product Entry].ProductID, Process.PartNumber;
Dependencies
- None
Parameters
- None
What it does
SQL Query Description
This SQL query retrieves data from multiple tables and performs calculations to produce the desired output. Here's a detailed description of what the code does:
Overview
The query joins three tables: Process
, [SP Product Entry]
, and [SP Units]
. It filters out obsolete products, calculates the actual weight (AW) and gross weight (GW) for each product, and sorts the results by product ID and part number.
Table Joins and Filtering
- The query starts by joining the
Process
table with the[SP Product Entry]
table on thePartNumber
column. - It then left joins the
[SP Units]
table with the[SP Product Entry]
table on theProductID
column. This allows for products without units data to still be included in the results.
Filtering
The query filters out obsolete products by applying the condition [SP Product Entry].Obsolete = 0
. Only products marked as not obsolete are included in the results.
Calculations
Two calculations are performed:
- Actual Weight (AW) per Year: The product of
[PartsPerUnit]
,[UnitsPerYear]
, and[ActualWt]
is calculated and aliased asAW/Year
. - Gross Weight (GW) per Year: Similarly, the product of
[PartsPerUnit]
,[UnitsPerYear]
, and[GrossWt]
is calculated and aliased asGW/Year
.
Sorting
The results are sorted by two columns:
- Product ID: Products are sorted in ascending order based on their IDs.
- Part Number: For each product, the parts are sorted in ascending order based on their numbers.
Output
The query returns a result set with the following columns:
[SP Product Entry].Obsolete
: A boolean indicating whether the product is obsolete (0 = not obsolete).[SP Product Entry].ProductID
: The ID of the product.[SP Product Entry].PartsPerUnit
: The number of parts per unit for the product.Process.*
: All columns from theProcess
table, exceptPartNumber
.[SP Units].UnitsPerYear
: The units per year for the product (if available).AW/Year
: The actual weight of the product per year.GW/Year
: The gross weight of the product per year.
Note that this query assumes the existence of specific columns in each table and may require adjustments based on your actual database schema.