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
Post a Comment