This is a SQL query, specifically formatted for Microsoft Access,...
This is a SQL query, specifically formatted for Microsoft Access, used for generating a report by aggregating and joining data from multiple tables. Below is an explanation of what this query does:
High-Level Summary
This query combines data from several tables, performs conditional mappings, groups data at a monthly level, and aggregates quantities (Qty
). It associates part numbers with specific customers (PWA
, PWC
, or GE
), and outputs the data along with manufacturing site details and part relationships. The result aggregates and combines data based on the monthly requested quantities and specific criteria.
Detailed Breakdown
-
From Clause and Outer Query (
RIGHT JOIN
):- The main table being queried is
PartNum_IC_Xref
(aliased asXref
). This table contains cross-referenced part numbers (IC_PN
,DTL_PN
, etc.). - The
RIGHT JOIN
combines it with a subquery (A
) that contains aggregated data from multiple sources. The join condition isA.[ICPN] = Xref.[IC_ID]
.
- The main table being queried is
-
Data Selection:
- Fields pulled in the SELECT clause include:
- Date field (
R_Date
): The monthly bucketed reporting date. - Customer mapping:
IIF(A.[Cust] = 1, "PWA", IIF(A.[Cust] = 2, "PWC", "GE"))
maps customer codes to human-readable names (PWA
,PWC
, orGE
). - Several part number fields from
Xref
(internal part number, detailed part number, manufacturing part number). - Manufacturing site and aggregated quantity (
Qty1
).
- Date field (
- Fields pulled in the SELECT clause include:
-
Subquery (Multiple UNIONs to Combine Data):
-
The subquery combines results from individual SELECT statements, each representing data for a specific customer or source. Each of these queries:
- Aggregates quantities by customer and monthly reporting date.
- Aligns customer codes and part numbers across datasets.
-
Subquery 1: Monthly quantities by
Requested Date
for thePWA
customer (Cust = 1
). This aggregates data from thePWAMRPReport
andPart_Number_IC
tables for future requests (>= next month). -
Subquery 2: Execution data for the
PWA
customer based on a specific report date ([Forms]![Ref_Frm_Qry]![PD_DropDown_Date], a user input). Data includes quantities where the requested date is in the past. -
Subquery 3: Forecast data for the
PWC
customer (Cust = 2
). This looks at data from the future (Stat Date >= next month
) and aggregates outstanding quantities (Outstand Qty
) from thePWC_Fcast
table. -
Subquery 4: Delivery data for the
PWC
customer. It pulls quantities based on a specific report date ([Forms]![Ref_Frm_Qry]![PD_DropDown_Date]) and other criteria. -
Subquery 5: Scheduling data for the
GE
customer (Cust = 3
). This aggregates due quantities (Net Due Quantity
) from GE scheduling lines (GESchedLines
) excluding received items.
-
-
Groupings and Aggregations:
- Each subquery groups by the monthly reporting date (
DateSerial(Year(...), Month(...), 1)
) and part ID or number. Quantities (Qty
) are summed up.
- Each subquery groups by the monthly reporting date (
-
Final Output:
- The final results combine all of this data:
- For each monthly reporting date (
R_Date
). - For each customer (
Cust
) mapped to the friendly namesPWA
,PWC
, orGE
. - With respective part numbers and quantities.
- For each monthly reporting date (
- The final results combine all of this data:
Purpose
This query likely generates a report summarizing forecasted or requested production/part quantities by month for different customers (PWA
, PWC
, or GE
). It associates these quantities with standardized part numbers and their manufacturing sites. The purpose might be:
- Facilitating demand planning or manufacturing execution.
- Aggregating customer data sourced from multiple tables and formats.
- Providing a unified view for decision-making.
Key Notes
- The query depends heavily on user-supplied data through a form (
[Forms]![Ref_Frm_Qry]![PD_DropDown_Date]
). - It uses Access-specific functions like
DateSerial
,IIF
, and Access form references ([Forms]!
). - Multiple UNION queries combine data from different customers or sources into a single consistent result format.