What means this query?
@numberx = @numberx -1
UPDATE th
SET @numberX= numberY= @numberX + 1
FROM Table1 th
INNER JOIN Table2 td ON th.Id = td.idth
WHERE td.anything = @anything
At line 3, what is this “double equality”?
And what is this “from” and “inner” on an UPDATE?
It’s a multiple table update for assigning consecutive numbers to each row in
Table1where the corresponding row inTable2has a specific value for the columnanything.For each matching row it sets the column
numberYto the value of@numberX + 1. It also reassigns that value back to@numberX, which causes@numberXto be incremented for each row.This is known as a “quirky update”. It is an undocumented and not guaranteed approach to generate running totals. In 2012
SUM() OVER (ORDER BY ...)should be used instead.