PSLine2000Documentation/Queries/Util Make Select 1.md

58 lines
2.6 KiB
Markdown

# Util Make Select 1
Analysis generated on: 4/2/2025 10:14:37 AM
---
## SQL Statement
```sql
SELECT Left$([PartNumber],7) AS prt, Right$([PartNumber],1) AS Rev, [Util Selection 0].* INTO [Util Selection 1]
FROM [Util Selection 0]
WHERE ((([Util Selection 0].Flag)="1"))
ORDER BY Left$([PartNumber],7), Right$([PartNumber],1) DESC;
```
## Dependencies
- *None*
## Parameters
- *None*
## What it does
**SQL Code Explanation**
==========================
### Overview
This SQL code retrieves data from a table named `[Util Selection 0]`, filters it based on a specific condition, and rearranges the output columns to display part numbers in a unique format.
### Column Transformations
The code performs two transformations on the `PartNumber` column:
* **Left Transformation**: The `Left$([PartNumber],7)` function extracts the first 7 characters from the `PartNumber`. This is used as the `prt` alias.
* **Right Transformation**: The `Right$([PartNumber],1)` function extracts the last character from the `PartNumber`. This is used as the `Rev` alias.
### Data Filtering
The code filters the data in `[Util Selection 0]` table to only include rows where the `Flag` column value is equal to `"1"`. The filtered data is stored in a temporary table named `[Util Selection 1]`.
### Sorting and Ordering
After filtering, the code sorts the data in ascending order by the `Left$([PartNumber],7)` transformed part numbers (`prt`) and then in descending order by the `Right$([PartNumber],1)` transformed character (`Rev`).
**SQL Code Breakdown**
------------------------
| Step | SQL Command | Description |
| --- | --- | --- |
| 1 | `SELECT Left$([PartNumber],7) AS prt, Right$([PartNumber],1) AS Rev` | Extracts the first 7 characters and last character from the `PartNumber`. |
| 2 | `INTO [Util Selection 1]` | Stages the data into a temporary table named `[Util Selection 1]`. |
| 3 | `FROM [Util Selection 0]` | Specifies the original table as the source of the data. |
| 4 | `WHERE ((([Util Selection 0].Flag)="1"))` | Filters the data to only include rows where the `Flag` column value is `"1"`. |
| 5 | `ORDER BY Left$([PartNumber],7), Right$([PartNumber],1) DESC` | Sorts the filtered data in ascending order by the transformed part numbers (`prt`) and then in descending order by the transformed character (`Rev`). |
**Example Use Case**
--------------------
This SQL code can be used in a scenario where you need to:
* Filter and transform data related to parts with specific properties (e.g., flagged as "1").
* Rearrange the output columns to display part numbers in a unique format.
* Sort the filtered data based on both transformed columns.