I want to update the bottom/the last row in my table. I have try to implement this solution, but nothing seems as 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 have till now working is:
UPDATE @ResultTable
SET PeriodLastDate=DATEADD(DAY,-1,PeriodLastDate)
WHERE PeriodID=(SELECT COUNT(PeriodID) FROM @ResultTable)-1
but this will not always works, as in my function some of the records are deleted and I am not always having PeriodIDs incremented with 1.
What about :
UPDATE ResultTable SET PeriodLastDate='NewValue' WHERE ID= (SELECT MAX(ID) FROM ResultTable)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With