码迷,mamicode.com
首页 > 数据库 > 详细

SqlServer 跨服务器查询

时间:2016-07-07 09:42:26      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:

服务器A,服务器B

select * from(
   select a.ID as Hid,a.subjectid as Hsubjectid,b.ID as Lid,b.subjectid as Lsubjectid,c.* FROM OPENROWSET(‘MSDASQL‘,
   ‘DRIVER={SQL Server};SERVER=A;UID=sa;PWD=***‘,
   dbName) as a  left join OPENROWSET(‘MSDASQL‘,
   ‘DRIVER={SQL Server};SERVER=B;UID=sa;PWD=***‘,
   dbName) as b  on a.subjectid = b.subjectid  
   left join OPENROWSET(‘MSDASQL‘,
   ‘DRIVER={SQL Server};SERVER=B;UID=sa;PWD=***‘,
   dbName) as c
   on c.CourseID = a.ID where a.subjectid = b.subjectid and c.CourseID = a.ID) as T 

SqlServer 跨服务器查询

标签:

原文地址:http://www.cnblogs.com/shiyige-216/p/5648767.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!