How to use Update Select statement based on more tables in SQL Server?
I have three tables such as TableA, TableB and TableC. I want to update one column in TableA from the column value in TableC. But there is no direct rel开发者_如何学Cationship b/w TableA and TableC. But TableB has relationship with both the tables A and C. How can I update? The structure of the tables are given below:
TableA: TableB: TableC:
---------- ----------- ----------
ItemID ID ID
Name ItemDetailID D1
Quantity TotalQty D2
Rate TotalAmount D3
ItemDetailID TotalWeight Quantity
Here I want to update TableA Column "Quantity" with TableC column value "Quantity". I used Update select statement using two tables. But not like this. How to do? Please give suggestions...
Something like:
Update a
set a.Quantity = c.Quantity
from TableA a
join TableB b on b.ItemDetailId = a.ItemDetailId
join TableC c on c.ID = b.ID
Update a
Set a.Quantity = c.Quantity
From TableA a
Inner Join TableB b on b.ItemDetailId = a.ItemDetailId
Inner Join TableC c on c.ID = b.ID
精彩评论