我有一个由数字1,2,3,5,6,9 ......组成的列。
请告知SQL存储过程如何从1开始更新此列,依此类推where ORDERBY date_column(date)
。
答案 0 :(得分:0)
你可以使用这样的东西。请按方向检查订单,如果2行包含相同的日期值,该怎么办(您可以在ORDER BY
内的OVER
子句中添加其他表达式。
CREATE PROCEDURE dbo.ResetNumber
AS
BEGIN
;WITH Ranking AS
(
SELECT
T.ColumnWhichHoldsTheValue,
Ranking = ROW_NUMBER() OVER (ORDER BY T.date_column ASC) -- Please see if it should be ASC or DESC
FROM
YourTable AS T
)
UPDATE T SET
ColumnWhichHoldsTheValue = T.Ranking
FROM
Ranking AS T
END