我正在尝试将记录从一个表更新到同一数据库中的另一个表。我究竟做错了什么? SQLMS2017不喜欢第4行上的[dbo]。[TempSupplier3]。[addaddress]。我已经尝试过包括别名的Alsorts。表格肯定存在,因为我可以选择它并拖动它。不断获取的多部分标识符无法绑定。
UPDATE
fds.Address
SET
fds.Address.addaddress = [dbo].[TempSupplier3].[addaddress]
FROM
dbo.TempSupplier3 TS
INNER JOIN
fds.Address AS FA
ON
TS.addshortname = FA.addShortName
WHERE
FA.addshortname = 'yes'
答案 0 :(得分:1)
使用连接语法进行更新将是这样...别名应这样
UPDATE
FA
SET
FA.addaddress = ts .[addaddress]
FROM
dbo.TempSupplier3 TS
INNER JOIN
[Address] FA
ON
TS.addshortname = FA.addShortName
WHERE
FA.addshortname = 'yes'
答案 1 :(得分:1)
您要为表加别名,但不使用别名...
将其更改为:
UPDATE FA
SET FA.addaddress = TS.[addaddress]
FROM
dbo.TempSupplier3 TS
INNER JOIN
fds.Address AS FA ON
TS.addshortname = FA.addShortName
WHERE
FA.addshortname = 'yes'
答案 2 :(得分:1)
我相信问题在于,一旦您将表别名作为其他名称,就需要继续使用该别名。因此,尝试这样做:
UPDATE FA
SET addaddress = TS.[addaddress]
FROM dbo.TempSupplier3 TS
INNER JOIN fds.Address AS FA
ON TS.addshortname = FA.addShortName
WHERE
FA.addshortname = 'yes';
或者,如果要在任何地方使用完全限定的表名,请使用以下命令:
UPDATE fds.Address
SET addaddress = dbo.TempSupplier3.[addaddress]
FROM dbo.TempSupplier3
INNER JOIN fds.Address
ON dbo.TempSupplier3.addshortname = fds.Address.addShortName
WHERE
fds.Address.addshortname = 'yes';