根据连接表中的条件更新表

时间:2016-01-24 10:05:19

标签: sql-server

我有以下

客户1-许多客户地址

客户1-许多客户电话

我想根据CustomerCalls中列的值更新CustomerAddresses。如下所示:

Update CustomerAddresses
Set CustomerAddresses.PostCode = 'xxx'
Where CustomerCalls.CallType = 'x'

1 个答案:

答案 0 :(得分:2)

您可以在更新语句中使用from子句,允许您也使用连接。像这样的东西应该做的伎俩(虽然我不得不猜测列名......)

UPDATE CustomerAddresses
SET CustomerAddresses.PostCode = 'xxx'
FROM CustomerAddresses 
INNER JOIN Customers ON Customers.Address = CustomerAddresses.AddressId
INNER JOIN CustomerCalls ON Customers.Calls = CustomerCalls.CallId
WHERE CustomerCalls.CallType = 'x'