Below is my code and I am again new to SQL so I am hitting things that I am not sure how to do. I have an input field (@USku) that is not in the table I have to update so I take that field and access another table to get the field I can use to update the correct record in the table. I have declared a variable to save that field so I can use that info to update the Quantity on Hand for that record. However I do not think the value in that saved variable is correct at the time of the update call. If I take @SaveSku and replace it with a constant the Update is executed correctly. Can anyone help and see what I can do to change my code.
declare @SaveSku varchar(50)
SELECT dbo.Inventory.SkuId, SkuCode, QuantityOnHand, LocationId, CompanyId, dbo.Sku.SkuId as SaveSku
FROM [twretPRD].[dbo].[Inventory] LEFT OUTER JOIN
[twretPRD].[dbo].[Sku] ON dbo.Inventory.SkuId = dbo.Sku.SkuId
WHERE SkuCode = @USku and LocationID = @Location
SET QuantityOnHand = QuantityOnHand - @qoh
WHERE LocationId = @Location and SkuId = @SaveSku