I want to update the bottom / last row in my table. I am trying to implement this solution, but nothing seems to be the correct syntax:
UPDATE TOP(1) @ResultTable SET PeriodLastDate=DATEADD(DAY,-1,PeriodLastDate) ORDER BY PeriodID DESC
OR
UPDATE TOP(1) @ResultTable SET PeriodLastDate=DATEADD(DAY,-1,PeriodLastDate) FROM @ResultTable ORDER BY PeriodID DESC
What I'm still working on:
UPDATE @ResultTable SET PeriodLastDate=DATEADD(DAY,-1,PeriodLastDate) WHERE PeriodID=(SELECT COUNT(PeriodID) FROM @ResultTable)-1
but this will not always work, as in my function some records are deleted, and I do not always have PeriodID in increments of 1.
gotqn source share