shlogg · Early preview
Judy @esproc_spl

MSSQL Computed Column Flag For Duplicate Rows Detection

Create computed column Flag in MSSQL: group rows by Serial_Number, record "Y" for duplicate Last_update_date values, otherwise "N".

In MSSQL, my_table table has three columns (as shown below). Serial_Number is the grouping field; Id and Last_update_date contain detail data, and there are duplicate values in the last field.

We need to add a computed column named Flag. The rule is like this: Group rows by Serial_Number and record Flag value as "Y" for each record in this group if there are duplicate Last_update_date values; otherwise record Flag value as "N".

Write the following SPL code:

group()function groups rows without aggregation; @u option retains the original order of the records for the result. groups() function...