我有3个数据库
- ECPNWEB
- ECPNDB
- ECPNPOS
以及3个表
- account -> ECPNWEB
- branch -> ECPNDB
- terminal -> ECPNPOS
并且表格有多列
- account (accntid,managedby,account,first,last,....)
- branch(branch_code,company_code,name,distributor,cutoff,....)
- terminal(retail,brand,model,serial,status,....)
我想做的就是获取特定的专栏。 我想要的输出是:
managedby for table account and ECPNWEB database
name for table branch and ECPNDB database
model for table terminal and ECPNPOS database..
喜欢这个
|managedby|name|model
提前致谢
答案 0 :(得分:1)
sp_addlinkedserver()
就是您所需要的exec sp_addlinkedserver @server = '*server_name*'
// ---将* server_name *替换为你的select * from [server].[database].[schema].[table]
我不是这样,但试试这个并告诉我什么是o / p。例如,您可以尝试这种方式
SELECT firstdb.*, seconddb.*
FROM Server1.Database1.dbo.myTable AS firstdb
INNER JOIN Server2.Database2.dbo.myTable AS seconddb
ON firstdb.id = seconddb.id
EDIT2:试试这个,不确定这会给你想要的结果,没有经过测试......用你的替换* column_name *
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)