54 lines
2.7 KiB
Markdown
54 lines
2.7 KiB
Markdown
# Metals
|
|
Analysis generated on: 4/2/2025 10:04:19 AM
|
|
---
|
|
## SQL Statement
|
|
```sql
|
|
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
|
|
- [[Tables/[RMSFILES__EGMMP1A0]]]
|
|
- [[Tables/[RMSFILES__MSPMLVPT]]]
|
|
## 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:
|
|
|
|
1. `[Metals Header]`: contains metadata about metals.
|
|
2. `[RMSFILES#_EGMMP1A0]`: contains additional data related to metals, including production and cost information.
|
|
3. `[Metals Not Tracked]`: contains data about metals that are not tracked (e.g., missing or outdated information).
|
|
4. `[RMSFILES#_MSPMLVPT]`: contains production data for specific metals.
|
|
|
|
### Join Order
|
|
|
|
The query uses a series of left joins to combine data from the tables:
|
|
|
|
1. First, it joins `[Metals Header]` with `[RMSFILES#_EGMMP1A0]` on the `PartNo` column.
|
|
2. Next, it joins the result set with `[Metals Not Tracked]` on the same `PartNo` column.
|
|
3. Finally, it joins the previous result set with `[RMSFILES#_MSPMLVPT]` on the `PRDNO` column.
|
|
|
|
### Calculated Columns
|
|
|
|
The query calculates two new columns:
|
|
|
|
1. `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.
|
|
2. `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 original `Dens` 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.
|