How to use ROW_NUMBER() in UPDATE clause? [duplicate]
问题 This question already has answers here : SQL Update with row_number() (8 answers) Closed 4 years ago . ROW_NUMBER() is only for used in the SELECT clause in MS SQL Server , but I want to use it for update like the following: Update MyTab Set MyNo = 123 + ROW_NUMBER() over (Order By ID) Where a=b; then I got Error like, Windowed functions can only appear in the SELECT or ORDER BY clauses. How to use ROW_NUMBER() in UPDATE clause? 回答1: DECLARE @MyTable TABLE ( ID INT IDENTITY(2,2) PRIMARY KEY,