sql linked server join query

十年热恋 提交于 2019-12-28 16:12:14

问题


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

My query:

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]

The errors:

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?

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


回答1:


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];


来源:https://stackoverflow.com/questions/21137592/sql-linked-server-join-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!