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