UPDATE/JOIN中的另一台服务器上的表中引用列(SQL Server)
问题描述:
我熟悉4部分命名,但每次尝试引用列时都会出错。例如:UPDATE/JOIN中的另一台服务器上的表中引用列(SQL Server)
UPDATE my_table
SET my_table.column1 = otherserver.otherdatabase.dbo.othertable.column1
FROM my_table INNER JOIN otherserver.otherdatabase.dbo.othertable
ON my_table.column2 = otherserver.otherdatabase.dbo.othertable.column2
这引发以下错误:
The multi-part identifier "otherserver.otherdatabase.dbo.othertable.column1" could not be bound.
我永远不会有麻烦,如果我只引用一个表,但是当我追加的列名,它总是抛出一个错误。有任何想法吗? SQL Server 2008中
答
只需使用表名时,你有资格的列。
UPDATE my_table
SET my_table.column1 = othertable.column1
FROM my_table INNER JOIN otherserver.otherdatabase.dbo.othertable
ON my_table.column2 = othertable.column2
或使用别名。
UPDATE my_table
SET my_table.column1 = OT.column1
FROM my_table INNER JOIN otherserver.otherdatabase.dbo.othertable as OT
ON my_table.column2 = OT.column2
答
使用表的别名,然后访问列:
UPDATE my_table
SET my_table.column1 = A.column1
FROM my_table INNER JOIN otherserver.otherdatabase.dbo.othertable A
ON my_table.column2 = A.column2
+0
作品也很棒!谢谢! – eek142 2012-03-13 13:37:21
你能看到'select column1 from otherserver.otherdatabase.dbo.othertable'吗? – garik 2012-03-13 13:28:41
是的,这工作正常。 – eek142 2012-03-13 13:32:27