SqlServer 跨服务器查询

服务器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 

posted @ 2016-07-07 09:05  之广  阅读(228)  评论(0编辑  收藏  举报
我的博客——易之广