2014-01-15 2 views
4

로컬 서버에 연결된 쿼리를 실행하는 중 연결된 서버의 DB에 문제가 있습니다.SQL 링크 된 서버 가입 쿼리

내 쿼리 :

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. 

가 올바르지 않습니다하지만 난 그것을 해결하기 위해 드릴 수 없습니다. 누군가 해결책을 제안 할 수 있습니까?

다른 서버에있는 2 개의 데이터베이스에 대해 선택 쿼리를 실행하는 것이 더 나은 해결책이 있다면 언급하십시오.

답변

9

이 사용하는 테이블 별칭을 작성하십시오 :

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

감사합니다, 그 누락 된 링크이었다. 테이블 별칭. –