我想更新表格的底部/最后一行.我已经尝试实现
this解决方案,但似乎没有任何正确的语法:
UPDATE TOP(1) @ResultTable SET PeriodLastDate=DATEADD(DAY,-1,PeriodLastDate) ORDER BY PeriodID DESC
要么
UPDATE TOP(1) @ResultTable SET PeriodLastDate=DATEADD(DAY,PeriodLastDate) FROM @ResultTable ORDER BY PeriodID DESC
我到现在所做的工作是:
UPDATE @ResultTable SET PeriodLastDate=DATEADD(DAY,PeriodLastDate) WHERE PeriodID=(SELECT COUNT(PeriodID) FROM @ResultTable)-1
解决方法
;WITH CTE AS ( SELECT TOP 1 * FROM @ResultTable ORDER BY PeriodID DESC ) UPDATE CTE SET PeriodLastDate=DATEADD(DAY,PeriodLastDate)