Skip to content
Advertisement

Add a Unique ID Number To Duplicate Rows SQL

I have the below table called TestTable and need to update the MsgNum column to have a unique number ordered by the date column but grouped by the JobNum.

Below is what I need to end up with.

I have the below that seems to work to generate the ID number that but suck on how to update the table MsgNum column with the ID number.

Advertisement

Answer

You can use row_number() and an updateable common-table-expression:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement