从不同的表和不同的数据库中选择特定的列 [英] selecting specific columns from different tables and different database
本文介绍了从不同的表和不同的数据库中选择特定的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 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,....)
我想要做的就是获取特定的列.,我想要的输出是:
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..
像这样
|managedby|name|model
提前致谢
推荐答案
sp_addlinkedserver()
正是您所需要的exec sp_addlinkedserver @server = '*server_name*'
//---用你的替换 *server_name*- 它看起来像这样:例如
select * from [server].[database].[schema].[table]
- 查看此链接 http://msdn.microsoft.com/en-我们/图书馆/ms190479.aspx
sp_addlinkedserver()
is what you needexec sp_addlinkedserver @server = '*server_name*'
//---replace *server_name* with yours- it will look like this: e.g.
select * from [server].[database].[schema].[table]
- Check out this link http://msdn.microsoft.com/en-us/library/ms190479.aspx
我不关心它,但试试这个并告诉我什么是 o/p.比如你可以试试这种方式
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
试试这个,不确定这会给你想要的结果,没有测试......用你的替换 *column_name*
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)
这篇关于从不同的表和不同的数据库中选择特定的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文