--创建分布式连接
--数据库名:TOPSKY0722 ip:172.18.1.7
--数据库名:TOPSKY0722 ip:172.18.1.7
exec sp_addlinkedserver 'TOPSKY0722','','SQLOLEDB','172.18.1.7'
exec sp_addlinkedsrvlogin 'TOPSKY0722','false',null,'futian_user','futian'
--建立一个临时表 查询出出诊的医生 科室 (跨数据库查询)
select gz.GKHM,gz.XM,gz.GZKS,kb.KSMC into gzrybak from TOPSKY0722.futian_user.GZRY as gz,TOPSKY0722.futian_user.KB as kb
where gz.GZKS=kb.BH
and gz.GKHM in(select GZRY from TOPSKY0722.futian_user.MZ_GHYSXXB)