sql链接服务器联接查询 [英] sql linked server join query

查看:74
本文介绍了sql链接服务器联接查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将本地数据库与链接服务器中的数据库联接在一起时,在运行任何查询时遇到问题.

I am having issues running any query on joining a local DB with a DB from a linked server.

我的查询:

SELECT 

        [LocalDatabase].[dbo].[Record].[Project_ID],
        [LinkedServer].[Reporting].[dbo].[Active].[Name]

        FROM [LocalDatabase].[dbo].[Record] inner join 
             [LinkedServer].[Reporting].[dbo].[Active] ON
             [LocalDatabase].[dbo].[Record].[Project_ID] = [LinkedServer].[Reporting].[dbo].[Active].[Delivery_Number]

错误:

Msg 4104, Level 16, State 1, Line 9
The multi-part identifier "LinkedServer.Reporting.dbo.Active.Delivery_Number" could not be bound.
Msg 4104, Level 16, State 1, Line 5
The multi-part identifier "LinkedServer.Reporting.dbo.Active.Name" could not be bound.

我猜我的语法不正确,但是我无法修复它. 有人可以提出解决方案吗?

I am guessing my syntax is incorrect but I am unable to fix it. Can someone please suggest a solution?

如果有更好的解决方案可以在不同服务器上的2个数据库上运行选择查询,请提及.

If there is a better solution for me to run a select query on 2 databases which are on different servers, please mention it.

推荐答案

尝试使用表别名来编写:

Try writing this using table aliases:

SELECT r.[Project_ID], a.[Name]
FROM [LocalDatabase].[dbo].[Record] r inner join 
     [LinkedServer].[Reporting].[dbo].[Active] a
     ON r.[Project_ID] = a.[Delivery_Number];

这篇关于sql链接服务器联接查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆