62 lines
2.9 KiB
Markdown
62 lines
2.9 KiB
Markdown
# SP Product Data
|
|
Analysis generated on: 4/2/2025 10:12:10 AM
|
|
---
|
|
## SQL Statement
|
|
```sql
|
|
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
|
|
|
|
1. The query starts by joining the `Process` table with the `[SP Product Entry]` table on the `PartNumber` column.
|
|
2. It then left joins the `[SP Units]` table with the `[SP Product Entry]` table on the `ProductID` 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:
|
|
|
|
1. **Actual Weight (AW) per Year**: The product of `[PartsPerUnit]`, `[UnitsPerYear]`, and `[ActualWt]` is calculated and aliased as `AW/Year`.
|
|
2. **Gross Weight (GW) per Year**: Similarly, the product of `[PartsPerUnit]`, `[UnitsPerYear]`, and `[GrossWt]` is calculated and aliased as `GW/Year`.
|
|
|
|
### Sorting
|
|
|
|
The results are sorted by two columns:
|
|
|
|
1. **Product ID**: Products are sorted in ascending order based on their IDs.
|
|
2. **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 the `Process` table, except `PartNumber`.
|
|
* `[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.
|