Skip to content
Advertisement

SQL: Increment ID only for new rows based on the count

Requirement: Generate new ID from the MAX ID for those Name doesn’t exist in the Target table and has count >1

Below is the Source data, The yellow highlighted are new rows, Those with count >1 are incremented with a new ID, and those with count =1 defaults to FM00000001

The expected result is highlighted in yellow in the Target table

I have generated the existing ID manually for one time , as I have to automate daily jobs so I need to generate incremental ID from MAX ID for those count >1

enter image description here

Advertisement

Answer

ok If I understand correctly , here is how you can do it :

for reference: Window Functions

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