Skip to content
Advertisement

How to update with order in SQL Server?

I am using SQL Server, and I have a table that looks like this:

I want to update id to have a sequence of rows ordered by distance asc, then i asc

I tried this

but I am getting an error

Incorrect syntax near “order”

How to fix that?

Advertisement

Answer

You need to use ROW_NUMBER inside a derived table or CTE.

e.g. as below

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