62 lines
2.5 KiB
Markdown
62 lines
2.5 KiB
Markdown
# Query9
|
|
Analysis generated on: 4/2/2025 10:10:14 AM
|
|
---
|
|
## SQL Statement
|
|
```sql
|
|
SELECT Left(Left([PN],Len([pn])-1)+" ",15) AS Part, filter2.PN, Process.PartNumber, Process.GrossWt, Process.ActualWt INTO filter3a
|
|
FROM filter2 LEFT JOIN Process ON filter2.PN = Process.PartNumber;
|
|
|
|
```
|
|
## Dependencies
|
|
- [[Tables/filter2]]
|
|
- [[Tables/Process]]
|
|
## Parameters
|
|
- *None*
|
|
## What it does
|
|
**SQL Query Explanation**
|
|
=========================
|
|
|
|
### Overview
|
|
|
|
This SQL query joins two tables, `filter2` and `Process`, based on the `PN` column. It then selects and transforms data from both tables to create a new table, `filter3a`.
|
|
|
|
### Step-by-Step Breakdown
|
|
|
|
1. **Selecting Data**
|
|
```sql
|
|
SELECT
|
|
Left(Left([PN],Len([pn])-1)+" ",15) AS Part,
|
|
```
|
|
This line selects the `PartNumber` column from both tables using a combination of `LEFT` and `LEN` functions.
|
|
|
|
* The outermost `LEFT` function takes two arguments: the column name (`[PN]`) and its length (`Len([pn])-1`). It returns the leftmost occurrence of the specified string within that column, truncating it to 15 characters (including leading spaces).
|
|
* The inner `LEFT` function applies the same logic to the `PartNumber` column from both tables.
|
|
2. **Joining Tables**
|
|
```sql
|
|
FROM filter2 LEFT JOIN Process ON filter2.PN = Process.PartNumber;
|
|
```
|
|
This line joins the two tables based on the common column `PN`.
|
|
|
|
* The `LEFT JOIN` returns all rows from `filter2`, and the matching rows from `Process`.
|
|
* If there is no match, the result set will contain NULL values for the columns from `Process`.
|
|
3. **Creating a New Table**
|
|
```sql
|
|
INTO filter3a
|
|
```
|
|
This line creates a new table named `filter3a` to store the transformed data.
|
|
|
|
### Notes and Considerations
|
|
|
|
* The query assumes that the column names in both tables are spelled consistently (e.g., `[PN]` vs. `PartNumber`).
|
|
* The use of `LEFT` functions can lead to unexpected results if the specified string length is not consistent across all rows.
|
|
* This query does not include any filtering or sorting criteria; it simply joins and transforms the data.
|
|
|
|
### Example Output
|
|
|
|
| Part | PN | Process.PartNumber | Process.GrossWt | Process.ActualWt |
|
|
|------|-------|--------------------|------------------|-------------------|
|
|
| | PN | PartNumber | GrossWt | ActualWt |
|
|
| ... | ..... | .................... | ................... | ................... |
|
|
|
|
Note: The actual output will depend on the data in both `filter2` and `Process`.
|