简体   繁体   English

使用不同的服务器/数据库执行SQL任务

[英]Execute SQL task with different servers/database

Can i have my Execute SQL task look at 2 different connection manager. 我可以让我的Execute SQL任务查看2个不同的连接管理器。 For Instance: I need data from ServerA/DatabaseA querying against ServerB/DatabaseB. 对于实例:我需要来自ServerA / DatabaseA的数据查询ServerB / DatabaseB。 So now i need to write a query and retrieve data from both servers. 因此,现在我需要编写查询并从两个服务器检索数据。 Now 2 servers are not linked server, not necessarily. 现在2个服务器不是链接服务器,不一定。

Is this even possible, let me know, please. 这是否可能,请告诉我。

I've had to find a way to work around lack of linked servers before, and I have done something like this - Give it a try: 以前我不得不找到一种解决链接服务器不足的方法,并且我已经做了类似的尝试-试试看:

if object_id('tempdb..#mytemptable') is not null begin drop table #mytemptable end
select * into #mytemptable
from openrowset('SQLNCLI10','Server=TheOtherServersName;Trusted_Connection=yes;','SELECT * FROM FullyQualifiedName.dbo.MyTable')
/* Now use the temptable created on this server to do your join/subquery on whatever */
select * from MyOtherTable a
join #mytemptable b on a.id = b.id

Cheers! 干杯!

Add a Data Flow Task with separate Data Flow Source tasks for Server A and Server B . Server AServer B添加具有单独数据流源任务的数据流任务。 Then join results using the appropriate Data Flow Transformation task. 然后使用适当的“数据流转换”任务来合并结果。

As an example, this data flow takes a Flat File Source and OLEDB Source task, sorts results, then uses a Merge Join task for results. 例如,此数据流采用“ Flat File Source和“ OLEDB Source任务,对结果进行排序,然后对结果使用“ Merge Join任务。 It sounds like your implementation would require two OLEDB Sources or (ODBC, ADO NET, etc.). 听起来您的实现需要两个OLEDB Sources或(ODBC,ADO NET等)。

I like this method over the linked server or OPENROWSET , because you don't have to configure a linked server or enable Adhoc Distributed Queries on your SQL Server data sources. 我喜欢在链接服务器或OPENROWSET此方法,因为您不必在SQL Server数据源上配置链接服务器或启用Adhoc Distributed Queries

SSIS数据流

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM