开发者

Editing Multiple Rows by Their Order Index

Q: How would I go about using / applying the row number of each 开发者_Go百科row in a query to a certain column in the entire query?

I've added a screenshot to try and make things more obvious:

Editing Multiple Rows by Their Order Index

[The picture is only a simple example]

I would like to be able to directly use the value of the row number in such a context. (Iterate over the values, somehow?)

Thanks in advance. (Sorry if the question is a bit vague)


Try this :

;WITH TEST AS 
( 
SELECT *,  
       ROW_NUMBER() OVER (ORDER BY id DESC) AS RowNo 
FROM [UserTable]
) 
UPDATE TEST  
SET  myindex = RowNo
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜