|
here's an example of how you can perform a variable assignment in an sql update statement. each row processed by the update *also* performs the assignment.
the key is to use this syntax...
SET @x = MyIntegerColumn = @x + 1
this example just increments a value - so each row updated gets a higher value (most cases you would use an index for such a task).
read more...
ok, whoa, just picked this one up. usually variable assignment from a select statement is thought of as returning one final *single* value (whatever that happens to be).
if instead you perform some logical operations a variable in the meantime you can also continuously calculate and update a variable based on each subsequent row returned.
read more...