In Microsoft SQL Server:
I have seen this question several times, but can’t see anyone solving the problem:
UPDATE theTable t1
SET t1.col2 =
(SELECT (10 * (col1 + col2))
FROM theTable t2
WHERE t1.busRelAccount = t2.busRelAccount
AND t2.rowName = 'POS'
)
WHERE t1.busRelAccount = t2.busRelAccount
AND t1.rowName = 'INVENTORY'
;
Anyone having solved this problem without using CURSOR and loop the table?
Not 100% sure what you’re trying to do – but most likely, you could write your
UPDATEstatement much simpler – something like this:Basically, you define a JOIN between the two tables (both being the same table, really) and you then define how to update the column of
t1based on columns fromt2