PSLine2000Documentation/Queries/SP Util C1 Comparison.md

2.6 KiB

SP Util C1 Comparison

Analysis generated on: 4/2/2025 10:12:33 AM

SQL Statement

SELECT [SP Product Entry].Obsolete, [SP Product Entry].ProductID, [SP Product Entry].PartsPerUnit, [Util Selection C1].*, [SP Units].UnitsPerYear, [ActualWt]/[Usage] AS [AW/Unit], [GrossWt]/[Usage] AS [GW/Unit], [AW/Unit]*[Usage] AS [AW/Year], [GW/Unit]*[Usage] AS [GW/Year]
FROM ([SP Product Entry] LEFT JOIN [SP Units] ON [SP Product Entry].ProductID = [SP Units].ProductID) INNER JOIN [Util Selection C1] ON [SP Product Entry].PartNumber = [Util Selection C1].PartNumber
WHERE ((([SP Product Entry].Obsolete)=0))
ORDER BY [SP Product Entry].ProductID, [Util Selection C1].PartNumber;

Dependencies

  • None

Parameters

  • None

What it does

SQL Query Description

Overview

This SQL query retrieves data from three tables: SP Product Entry, SP Units, and Util Selection C1. It joins these tables based on common columns and applies filters to the results.

Query Steps

  1. Left Join: The query performs a left join between SP Product Entry and SP Units tables using the ProductID column as the joining criterion. This ensures that all records from SP Product Entry are included in the result, even if there is no matching record in SP Units.
  2. Inner Join: The query then joins the resulting table with Util Selection C1 table on the PartNumber column.
  3. Filtering: Only records from SP Product Entry where Obsolete is 0 are included in the result set, effectively excluding any obsolete products.
  4. Aggregation: The query calculates several aggregate values:
    • [AW/Unit]: Average weight per unit (calculated as [ActualWt]/[Usage])
    • [GW/Unit]: Gross weight per unit (calculated as [GrossWt]/[Usage])
    • [AW/Year]: Total average weight per year (calculated as [AW/Unit]*[Usage])
    • [GW/Year]: Total gross weight per year (calculated as [GW/Unit]*[Usage])
  5. Sorting: The results are sorted by ProductID and then by PartNumber.

Returned Columns

The query returns the following columns:

  • [SP Product Entry].Obsolete
  • [SP Product Entry].ProductID
  • [SP Product Entry].PartsPerUnit
  • Columns from Util Selection C1 table (all)
  • [SP Units].UnitsPerYear
  • [AW/Unit]
  • [GW/Unit]
  • [AW/Year]
  • [GW/Year]

Notes

The query uses several aliases for clarity:

  • [SP Product Entry]: Table name
  • [Util Selection C1]: Table name
  • [SP Units]: Table name
  • [ActualWt], [Usage], [GrossWt]: Column names
  • [AW/Unit], [GW/Unit], [AW/Year], [GW/Year]: Calculated column names

These aliases make the query easier to read and understand.