------------------------------------------------------------
--这段先执行
exec sp_configure ‘show advanced options‘,1
reconfigure
exec sp_configure ‘Ad Hoc Distributed Queries‘,1
reconfigure
------------------------------------------------------------
--这里写要执行的SQL语句
select *
from opendatasource(‘SQLOLEDB‘,‘server={server};uid={uid};pwd={pwd}‘).[DataBaseName].dbo.TableName
------------------------------------------------------------
--语句运行完以后执行这段关闭配置
exec sp_configure ‘Ad Hoc Distributed Queries‘,0
reconfigure
exec sp_configure ‘show advanced options‘,0
reconfigure
------------------------------------------------------------
SQL SERVER 执行远端数据库的SQL命令,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/xiebin1986/p/3818634.html