0

我正在寻找一种方法来更新包含city, state, zip, and county通过使用包含所有必要信息的不同表的表。

简而言之,我有一张表(我们称之为Table1),列出了所有的cities, states, and countiesby zip code(或任何你想要放入的顺序)。我想更新一个不同的表(调用它Table2),特别city, state, and county是使用zip code来自 Table1.

编辑:MS SQL 服务器

4

2 回答 2

4
UPDATE A
SET A.City = B.City
FROM Table2 AS A
INNER JOIN Table1 B
ON A.PostalCode = B.PostalCode
WHERE A.City IS NULL --Or Some Other Criteria
于 2012-08-22T22:17:09.590 回答
0

试试这个

UPDATE Table2
SET t2.City = t1.City,
t2.state= t1.state,
t2.county= t1.county

FROM Table2 AS t2
LEFT JOIN Table1 t1
ON t2.zipcode= t1.zipcode
于 2012-08-23T11:28:49.607 回答