PSLine2000Documentation/Queries/Util Make Duplicate Revisio...

66 lines
2.3 KiB
Markdown

# Util Make Duplicate Revision Remover 1
Analysis generated on: 4/2/2025 10:13:31 AM
---
## SQL Statement
```sql
SELECT Left$([PartNumber],7) AS prt, Trim$(Right$([PartNumber],1)) AS Rev, Process.PartNumber AS PartNumber
FROM Process
ORDER BY Left$([PartNumber],7), Trim$(Right$([PartNumber],1)) DESC;
```
## Dependencies
- [[Tables/Process]]
## Parameters
- *None*
## What it does
**SQL Query Description**
==========================
### Overview
This SQL query retrieves data from the `Process` table and performs various string manipulations to extract specific information.
### Query Breakdown
#### 1. SELECT Clause
The `SELECT` clause specifies the columns that will be retrieved from the database. In this case:
* `Left$([PartNumber],7)`: Extracts the first 7 characters of the `PartNumber` column and returns them as a string. The `$` symbol is used to denote string concatenation in SQL Server.
* `Trim$(Right$([PartNumber],1))`: Removes the last character (if any) from the `PartNumber` column using the `TRIM` function with the `$` symbol for string concatenation. This effectively extracts the rev number, which is the last digit of the part number.
#### 2. FROM Clause
The `FROM` clause specifies the table that contains the data to be retrieved:
* `Process`: The table from which to retrieve data.
#### 3. ORDER BY Clause
The `ORDER BY` clause sorts the retrieved data in ascending order based on two columns:
* `Left$([PartNumber],7)`: The first 7 characters of the part number.
* `Trim$(Right$([PartNumber],1))`: The last digit (rev number) of the part number. This column is sorted in descending order.
#### 4. AS Clause
The `AS` clause assigns aliases to the extracted columns:
* `prt`: Alias for the first 7 characters of the part number.
* `Rev`: Alias for the rev number (last digit of the part number).
* `PartNumber`: Alias for the original `PartNumber` column.
#### 5. ORDER BY Syntax
The specific syntax used for sorting in this query is an extension to the standard SQL syntax, allowing for sorting on multiple columns with a custom order.
### Example Output
| prt | Rev | PartNumber |
| --- | --- | --- |
| XYZ1234 | 4 | XYZ1234 |
| XYZ1233 | 3 | XYZ1233 |
| ... | ... | ... |
The output will show the first 7 characters of each part number followed by the last digit (rev number) in descending order.