How can I set a variable while doing an Update statement? I can\'t seem to figure out the syntax.
So I want something like this below but it\'s saying the syntax is
If you want to obtain something like this:
SET @tempVariable := 0;
UPDATE myTable SET col1 = 5, col2 = @tempVariable, @tempVariable := 100;
You can do a trick like this:
ALTER TABLE Proj ADD col3 numeric;
SET @tempVariable := 0;
UPDATE myTable SET col1 = 5, col2 = @tempVariable, col3 = @tempVariable := 100;
ALTER TABLE Proj DROP col3;
In this way, you can assign values to a variable without change attributes of a table. It is really usefull when setting dinamic values.
FOR EXAMPLE: @tempVariable := @otherVariable + 100;