查询LinkedServer时如何使用联接表

时间:2016-02-16 13:57:31

标签: sql sql-server sql-server-2008 linked-server

我有一个链接服务器LinkedServer1我想使用连接表进行查询。

我的查询示例:

   SELECT     dds.Invoice_Tb.Store_Number, dds.Invoice_Tb.Invoice_Number,
                 dds.Invoice_Detail_Tb.Invoice_Number AS Invoice
      FROM      [LinkedServer1].Database1.dds.Invoice_Tb INNER JOIN
                [LinkedServer1].Database1.dds.Invoice_Detail_Tb ON 
                [LinkedServer1].Database1.dds.Invoice_Tb.Invoice_Number = 
                [LinkedServer1].Database1.dds.Invoice_Detail_Tb.Invoice_Number

此查询在执行时给出了错误:

The multi-part identifier could not be bound for each of the above table references.  It references each table and column listed above.

如何使用表连接与链接服务器正确查询数据?

1 个答案:

答案 0 :(得分:3)

使用别名:

select  a.Store_Number,
        a.Invoice_Number,
        a.Invoice_Number as Invoice
from    [LinkedServer1].Database1.dds.Invoice_Tb as a
        inner join [LinkedServer1].Database1.dds.Invoice_Detail_Tb  as b on
           a.Invoice_Number = b.Invoice_Number