I have this select statement below which I would like to use to update the quantity of the products in another table, tablex
. I cannot seem to figure out how to match the product number from this query to the productnumber tablex and then add the quantity found in this statement to the existing quantity in tablex.
select
p.ProductNumber, sod.Quantity ,so.StateCode
from
SalesOrderDetail sod
right join
ProductAssociation pa on sod.ProductId = pa.ProductId
left join
Product p on pa.AssociatedProduct = p.ProductId
left join
SalesOrder so on so.SalesOrderId = sod.SalesOrderId
where
so.StateCode = '3'