如何使用SQL Server中的连接从不同服务器的两个不同数据库中选择数据? [英] how to select data from two different databases of different servers using join in SQL server?

查看:168
本文介绍了如何使用SQL Server中的连接从不同服务器的两个不同数据库中选择数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自差异服务器的两个差异数据库,

我需要使用连接查询从这些数据库中获取数据..bt我无法获取数据..我的查询是搜索..

I m having two diff databases from diff servers,
and i need to get data from those databases using join query ..bt i ma not able to fetch data..here is my query for search..

AS  
declare @Condition as varchar(max)                          
SET @Condition =''   
  
BEGIN  
 SET @Condition ='  
 select   
   Distinct FollowUpMaster.Followupid, 
    --EnquiredCourseMaster.Coursecatid,  
   FollowUpMaster.enqid,  
   SEnquiryMaster.EnqNo,  
   SEnquiryMaster.SName,  
   SEnquiryMaster.EnqDate,  
   FollowUpMaster.FollowUpMode,  
   FollowUpMaster.FollowUpDate,  
   FollowUpMaster.Remarks,  
   FollowUpMaster.NextFollowUpDate,  
 (emp.Fname +'' ''+ emp.Mname +'' ''+ emp.Lname) as Counsellor,  
   emp.Emp_ID,  
    ERPPROJECT.dbo.FollowUpMaster.FollowUpBy  
     
 from   
   ERPPROJECT.dbo.FollowUpMaster   
   Inner Join SEnquiryMaster on FollowUpMaster.Enqid=SEnquiryMaster.EnqId  
   inner join attendance.dbo.Employee_Master as emp on ERPPROJECT.dbo.FollowUpMaster.FollowUpBy=emp.Emp_ID
   INNER JOIN EnquiredCourseMaster ON SEnquiryMaster.EnqId=EnquiredCourseMaster.EnqId '  
    + '' + @Criteria + ''  
    
 print @Condition  
   
 exec(@Condition)  
   
 END







herer EmployeeMaster是diff数据库中的表..我在同一个数据库中也有相同的命名表,是否会产生冲突?




herer EmployeeMaster is the table from diff database..nd i have also the same named table in same database also ,does it make any conflict ?

推荐答案

http://stackoverflow.com/questions/1423907/how-do-you-join-tables-from-two-different-sql-server-instances-in-one-sql-query [< a href =http://stackoverflow.com/questions/1423907/how-do-you-join-tables-from-two-different-sql-server-instances-in-one-sql-querytarget =_ blank title =新窗口> ^ ]


这篇关于如何使用SQL Server中的连接从不同服务器的两个不同数据库中选择数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆