selecting specific columns from different tables a

2019-08-12 07:18发布

I have 3 Database

  - ECPNWEB
  - ECPNDB
  - ECPNPOS

and also 3 tables

  - account -> ECPNWEB
  - branch -> ECPNDB
  - terminal -> ECPNPOS

and the tables having multiple columns

  - account (accntid,managedby,account,first,last,....)
  - branch(branch_code,company_code,name,distributor,cutoff,....)
  - terminal(retail,brand,model,serial,status,....)

All I want to do is to get the specific column., my desired output is:

 managedby for table account and ECPNWEB database
 name for table branch and ECPNDB database
 model for table terminal and ECPNPOS database..

Like this

 |managedby|name|model

Thanks in advance

1条回答
forever°为你锁心
2楼-- · 2019-08-12 08:01
  1. sp_addlinkedserver() is what you need
  2. exec sp_addlinkedserver @server = '*server_name*' //---replace *server_name* with yours
  3. it will look like this: e.g. select * from [server].[database].[schema].[table]
  4. Check out this link http://msdn.microsoft.com/en-us/library/ms190479.aspx

I'm not about it but try this and tell me what is the o/p. For example you can try this way

SELECT firstdb.*, seconddb.*
FROM Server1.Database1.dbo.myTable AS firstdb
INNER JOIN Server2.Database2.dbo.myTable AS seconddb
   ON firstdb.id = seconddb.id

EDIT2: try this,not sure this will give u desired result, not tested... replace *column_name* with yours

SELECT account.managedby, branch.name, terminal.model FROM ECPNWEB.dbo.account, ECPNDB.dbo.branch, ECPNPOS.dbo.terminal AS a INNER JOIN account ON account.(column_name)=branch.(column_name)  INNER JOIN terminal ON account.(column_name)=terminal.(column_name)
查看更多
登录 后发表回答