简体   繁体   English

SQL Server:多个数据库之间的联接错误

[英]SQL Server : JOIN Between multiple databases error

I am trying to JOIN two different databases and am getting an error that I have not seen before. 我正在尝试加入两个不同的数据库,并且遇到了一个我从未见过的错误。 The SQL joins the database PDX_SAP_USER to asagdwpdx_prod . SQL将数据库PDX_SAP_USER连接到asagdwpdx_prod

The strange thing is that in the code below, if I exclude the table dbo.VW.PO_HEADER H and only include dbo.VW_PO_ITEM P , the query works fine, but the JOIN I need is on between the H and G tables. 奇怪的是,在下面的代码中,如果我排除了表dbo.VW.PO_HEADER H而仅包括dbo.VW_PO_ITEM P ,则查询工作正常,但是我需要的JOIN在H和G表之间。 It's when I include the PO Header table the issue arises. 这是当我包括PO Header表时出现的问题。

The error message is: 错误消息是:

Msg 7202, Level 11, State 2, Line 2 Msg 7202,第11级,州2,第2行
Could not find server 'PDX_SAP_USER' in sys.servers. 在sys.servers中找不到服务器“ PDX_SAP_USER”。 Verify that the correct server name was specified. 验证是否指定了正确的服务器名称。 If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers. 如有必要,执行存储过程sp_addlinkedserver将服务器添加到sys.servers。

The SQL code is: SQL代码是:

SELECT 
    G.order_no, 
    G.order_status, 
    G.cst_order_no,
    H.PO_NUMBER,
    P.PO_ITEM_NUMBER, 
    P.DEL_INDICATOR
FROM   
    (SELECT 
         order_no, 
         order_status, 
         cst_order_no
     FROM 
         asagdwpdx_prod.dbo.SimoxOrder1

     UNION ALL

     SELECT 
         order_no, 
         order_status, 
         cst_order_no
     FROM 
         asagdwpdx_prod.dbo.SimoxOrder2

     UNION ALL 

     SELECT 
         order_no, 
         order_status, 
         cst_order_no
     FROM 
         asagdwpdx_prod.dbo.SimoxOrder3) G 
JOIN 
    PDX_SAP_USER.dbo.VW.PO_HEADER H ON G.order_no = H.AHAG_NUMBER
JOIN 
    PDX_SAP_USER.dbo.VW_PO_ITEM P ON H.PO_NUMBER = P.PO_NUMBER 
WHERE 
    G.order_status = '90'

Thanks. 谢谢。

I think PDX_SAP_USER.dbo.VW.PO_HEADER is supposed to be PDX_SAP_USER.dbo.VW_PO_HEADER . 我认为PDX_SAP_USER.dbo.VW.PO_HEADER应该是PDX_SAP_USER.dbo.VW_PO_HEADER The extra period is making SQL Server think you're using 4-part naming to try to access a linked server. 多余的时间使SQL Server认为您正在使用4部分命名来尝试访问链接的服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM