当前位置:Gxlcms > 数据库问题 > SqlServer 跨服务器查询

SqlServer 跨服务器查询

时间:2021-07-01 10:21:17 帮助过:2人阅读

服务器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 跨服务器查询

标签:

人气教程排行