I need some help with one SQL statement to update one column (Total) based on two columns (Price, Quantity). I want to update the entire table. This is simply for data analysis and not a long term solution (I would use a trigger instead).
Current Table Data
ID ! Price ! Quantity ! Total
1 ! 2.00 ! 2 ! NULL
2 ! 3.00 ! 1 ! NULL
3 ! 5.00 ! 2 ! NULL
Updated Table Data
Table
ID ! Price ! Quantity ! Total
1 ! 2.00 ! 2 ! 4.00
2 ! 3.00 ! 1 ! 3.00
3 ! 5.00 ! 2 ! 10.00
My crappy SQL obviously doesn’t work
UPDATE Inventory
SET Total = (Price * Quantity)
This won’t work as I need to update the entire table. I guess I would need a sub-query ??
Any help would be appreciated. Thanks
What you posted seems fine to me.
will update the whole table row by row.