I need to update two table in parallel based on each other data.
Below is the table structure for both tables.
Product table:
ProductId | ProductQuantity | Min Price | Max Price
----------+-----------------+-----------+----------
1 | 122 | 58 | 585
2 | 548 | 45 | 856
Order table:
Order ID | ProductID | ProductOrderQuantity |OfferPrice | OrderProcessDate | Status
---------+-----------+----------------------+-----------+------------------+--------
1 | 2 | 35 | 75 | Null | Placed
2 | 1 | 752 | 258 | Null | Placed
I need to update Status
from Order
table to "Confirm/Reject" in below condition:
ProductOrderQuantity
should be less thanProductQuantity
in theProduct
tableOfferPrice
should be in betweenMin Price
andMax Price
If both conditions match, then update
Status
in theOrder
table toConfirm/Reject
andOrderProcessDate
as the date on which it processed
This update should be done sequentially to each row from order table and once status from a row updates to "confirmed" immediately update ProductQuantity
as ProductQuantity - ProductOrderQuantity