Assuming I have an orderline table with keys (order, orderline) that have restrictions on them preventing someone from updating them, I need to update a calculated column without updating the keys.
INSERT INTO ORDERLINES (ORDER, ORDERLINE, CALCULATED)
SELECT ORDER, ORDERLINE, ORDQTY * PRICE - RECQTY
FROM ORDERLINES
An order can have multiple lines on it, and so calculated has to be a per line calculation, but as far as I can tell, this statement attempts to update order and orderline to the same value they were.
>Solution :
update OrderLines
set Calculated = ORDQTY * PRICE - RECQTY
or better yet, make this actually a computed column that will always be up to date.
alter table OrderLines
add Calculated as ORDQTY * PRICE - RECQTY