Sql Server 跨库查询

使用Opendatasource函数

select * from OPENDATASOURCE(
         'SQLOLEDB',
         'Data Source=192.168.1.239;User ID=sa;Password=123'
         ).hzyl_hgb.dbo.hzyl_bc_zyjl where fkey not in
(select INPATIENT_SN from D504)
and issc=1 and scrq>='2009-01-01'

 

 exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
使用完毕后,记得要关闭它,因为这是一个安全隐患

exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure

posted @ 2009-06-29 15:18  无很  阅读(175)  评论(0)    收藏  举报