UPDATE (SELECT * , ROW_NUMBER() OVER ( ORDER BY PrintDate ) AS iRows FROM [ReceiptBill] WHERE [Stage] <> '报检') t SET t.OverdueType ='y' WHERE iRows=1
update后面那段select语句是可以查询到数据的。但是一起运行就会报错求大神解决下。
用cte吧
;with cte as ( SELECT * , ROW_NUMBER() OVER ( ORDER BY PrintDate ) AS iRows FROM [ReceiptBill] WHERE [Stage] <> '报检' ) UPDATE cte SET OverdueType ='y' WHERE iRows=1
谢谢解答,完美解决。能否稍微说下这个cte是什么意思 看不太懂呢。