Update consecutive numbering with UPDATE statement – MSSQL

I want to update a table with consecutive numbering starting at 1. The update has a where clause so only results that meet the clause will be renumbered. Can I accomplish this efficiently without using a temp table?


declare @i int = 0;
update TeamPraxisOfficeNames
set TmpNum = @i , @i = @i + 1
where tmpNum is null

, ,

No comments yet.

Leave a Reply

*