How to update, preserve a sequence


how update column preserve sequence? column, payororder sequence beginning 1, after rows deleted, there gaps in sequence:

1,3,6,11,23

need update these values 1,2,3,4,5

your appreciated.

using row_number() function can

 

  ;with cte as (select pk, sequence, row_number() over (order by sequence) as newseq from payororder)  update cte set sequence = newseq where sequence <> newseq  

 


premature optimization root of evil in programming. (c) donald knuth

naomi nosonovsky, sr. programmer-analyst

my blog


SQL Server  >  Transact-SQL



Comments

Popular posts from this blog

Motherboard replacement

Cannot create Full Text Search catalog after upgrading to V12 - Database is not fully started up or it is not in an ONLINE state

Remote Desktop App - Error 0x207 or 0x607