1.开通分布式查询权限
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
2.查询
select * from
openrowset( 'sqlOLEDB ','IP地址(服务器名)'; '用户名'; '密码',[数据库名].[dbo].[表名]) a
,openrowset( 'sqlOLEDB ',[数据库名].[dbo].[表名]) b
where *** GROUP by *** order by count(1) desc
4.关闭
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure