0

我有 3 台服务器:

 ECPAYSERV2 
 POSSQLSERVER 
 ECPAYSERV1 

3个数据库

 ECPNWEB
 ECPNPOS
 ECPNDB

和 3 张桌子

 account
 branch
 terminal

我也完成了链接服务器:

 ECPAYSERV2.ECPNWEB.dbo.account
 POSSQLSERVER.ECPNPOS.dbo.branch
 ECPAYSERV1.ECPNDB.dbo.terminal

应该看到的字段如下

 AccountID = ECPAYSERV2.ECPNWEB.dbo.account.(accntid)
 BranchID = ECPAYSERV2.ECPNWEB.dbo.branch.(branchid)
 TID = ECPAYSERV1.ECPNDB.dbo.terminal.(TID)
 Store # = POSSQLSERVER.ECPNPOS.dbo.branch.(Storeno)
 Store name = ECPAYSERV2.ECPNWEB.dbo.account.(accountholder)
 Branch name = ECPAYSERV2.ECPNWEB.dbo.brachn.(branchname) ,  POSSQLSERVER.ECPNPOS.dbo.branch.(branchname) , ECPAYSERV1.ECPNDB.dbo.terminal.(retail_store_code)

用括号括起来的数据是列。,

为了更清楚这一切是表中的列..

表:帐户

 |Accntid|managedby|Accountholder|Description|AccountType|ContactPerson|ContactNumber|EmailAddress|

表:分行

 |BranchID|BranchName|AccountID|StoreNo|Description|Status|

表:终端

 |TerminalID|TID|retail_store_code|t_distributor_code|

我想要的只是用正确的数据获取这个输出..

 |accntid|accountholder|tid|storeno|branchname|branchid|

这是我尝试但没有得到正确的输出

 SELECT account.accntid,account.accountholder,terminal.tid,branch.storeno,branch.branchname,branch1.branchid
 FROM ECPAYSERV2.ECPNWEB.dbo.account as account 
 INNER JOIN POSSQLSERVER.ECPNPOS.dbo.branch as branch
  ON account.accntid=branch.branchid 
 INNER JOIN ECPAYSERV2.ECPNWEB.dbo.branch as branch1
  ON account.accntid=branch1.branchid
 INNER JOIN ECPAYSERV1.ECPNDB.dbo.terminal as terminal 
  ON account.accntid=terminal.tid

请帮我解决这个问题谢谢:(

4

1 回答 1

1
SELECT
    account.accntid, account.accountholder, terminal.tid, branch.storeno, branch.branchname, branch1.branchid
FROM 
    ECPAYSERV2.ECPNWEB.dbo.account as account 
    INNER JOIN POSSQLSERVER.ECPNPOS.dbo.branch as branch
        ON account.accntid=branch.AccountID 
    INNER JOIN ECPAYSERV2.ECPNWEB.dbo.branch as branch1
        ON account.accntid=branch1.AccountID
    INNER JOIN ECPAYSERV1.ECPNDB.dbo.terminal as terminal 
        ON account.accntid=terminal.???

这 ???不正确,但不清楚终端的哪一列是帐户的FK。

于 2012-12-27T08:54:27.507 回答