2.7 KiB
2.7 KiB
Metals
Analysis generated on: 4/2/2025 10:04:19 AM
SQL Statement
SELECT [Metals Header].*, IIf(itsanull([Units])="SF",1,ITSAZERO([$NMWT]*(144/([length]*[Width])))) AS Dens, [RMSFILES#_EGMMP1A0].*, [Metals Not Tracked].IE_Density, IIf([Dens]=0,[IE_Density],[Dens]) AS Density, Itsazero([STDC1]) AS PricePerLB1
FROM (([Metals Header] LEFT JOIN [RMSFILES#_EGMMP1A0] ON [Metals Header].PartNo = [RMSFILES#_EGMMP1A0].[$PRD#]) LEFT JOIN [Metals Not Tracked] ON [Metals Header].PartNo = [Metals Not Tracked].PartNo) LEFT JOIN [RMSFILES#_MSPMLVPT] ON [Metals Header].PartNo = [RMSFILES#_MSPMLVPT].PRDNO;
Dependencies
Parameters
- None
What it does
SQL Query Description
This SQL query retrieves data from multiple tables and performs various calculations to generate a final result set. Here's a breakdown of the query:
Tables Involved
The query joins data from four tables:
[Metals Header]
: contains metadata about metals.[RMSFILES#_EGMMP1A0]
: contains additional data related to metals, including production and cost information.[Metals Not Tracked]
: contains data about metals that are not tracked (e.g., missing or outdated information).[RMSFILES#_MSPMLVPT]
: contains production data for specific metals.
Join Order
The query uses a series of left joins to combine data from the tables:
- First, it joins
[Metals Header]
with[RMSFILES#_EGMMP1A0]
on thePartNo
column. - Next, it joins the result set with
[Metals Not Tracked]
on the samePartNo
column. - Finally, it joins the previous result set with
[RMSFILES#_MSPMLVPT]
on thePRDNO
column.
Calculated Columns
The query calculates two new columns:
Dens
: calculates the density of the metal based on its weight, length, and width. The formula is:(144/([length]*[Width]))
. If[Units]
is "SF" (square feet), it returns 1.IIf([Dens]=0,[IE_Density],[Dens])
: applies an IF function to check if the calculated density (Dens
) is zero. If it is, it returns[IE_Density]
, otherwise, it returns the originalDens
value.
Final Result Set
The final result set includes all columns from [Metals Header]
, [RMSFILES#_EGMMP1A0]
, and [Metals Not Tracked]
. The calculated columns (Dens
and its variant) are also included. Finally, it adds a new column PricePerLB1
which is the result of applying an ITSAZERO function to the [STDC1]
column.
Notes
- The SQL query uses various data types (e.g.,
[Units]
is assumed to be a string). - The query assumes that some columns may be null, and it handles these cases using IF functions.
- The use of ITSAZERO and IIf functions suggests that the query is specific to a particular software or system.