UPDATE t
SET seq = GROUPSEQ
FROM (SELECT seq, [GroupId], row_number() OVER (PARTITION BY [GroupId] ORDER BY [GroupId]) GROUPSEQ
FROM [TableMemo]) t
No words wasted! Getting to the point about the work I do, the problems I deal with, and some links to posts about where I work.
Translate
Monday, August 23, 2021
TSQL - Assign A Sequential Number To Each Record In A Group
I needed to insert records from one table into another table and add a sequential number, field seq, that was group on an id field, GroupId. This CTE was the eastiest way that I found to add the number.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Thank you for commenting!