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

时间:2021-08-15 22:32:01

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. It's when I include the PO Header table the issue arises.

奇怪的是,在下面的代码中,如果我排除表dbo.VW.PO_HEADER H并且只包含dbo.VW_PO_ITEM P,则查询工作正常,但我需要的JOIN在H和G表之间。当我包含PO标题表时,问题出现了。

The error message is:

错误消息是:

Msg 7202, Level 11, State 2, Line 2
Could not find server 'PDX_SAP_USER' in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers.

消息7202,级别11,状态2,行2无法在sys.servers中找到服务器“PDX_SAP_USER”。验证是否指定了正确的服务器名称。如有必要,执行存储过程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.

1 个解决方案

#1


2  

I think PDX_SAP_USER.dbo.VW.PO_HEADER is supposed to be 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.

我认为PDX_SAP_USER.dbo.VW.PO_HEADER应该是PDX_SAP_USER.dbo.VW_PO_HEADER。额外的时间段使SQL Server认为您正在使用4部分命名来尝试访问链接服务器。

#1


2  

I think PDX_SAP_USER.dbo.VW.PO_HEADER is supposed to be 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.

我认为PDX_SAP_USER.dbo.VW.PO_HEADER应该是PDX_SAP_USER.dbo.VW_PO_HEADER。额外的时间段使SQL Server认为您正在使用4部分命名来尝试访问链接服务器。