Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi,
I have two ms sql table in two different instances. I want to join that two tables and get the result. Is it possible.

For example
Databse 1, Databse 2

Database 1 is in instance 1(sql Server 1)
Databse 2 is in instance 2 (sql server 2)


Thanks,
Posted
Updated 3-Aug-12 0:14am
v2
Comments
Herman<T>.Instance 3-Aug-12 6:07am    
why not joning in 1 query?
what do you mean by 2 different instances? two servers?
Soft009 3-Aug-12 6:12am    
same server two sql instances..

You should use a fully qualified name of the objects you are using.
Try this:
SQL
SELECT E.ID, E.Name, E.Address, C.Code, C.Mobile FROM Database1.DBO.tbEmployee E INNER JOIN Database2.DBO.tbEmployeeDtls C ON E.ID = C.ID


Refer the links below:
http://forums.asp.net/t/1254974.aspx/1[^]
http://stackoverflow.com/questions/5145637/querying-data-by-joining-two-tables-in-two-database-on-different-servers[^]


--Amit
 
Share this answer
 
Comments
Soft009 8-Aug-12 1:05am    
I can use this query when the databases are in the same instance(server) but in by case the databases are in two different instances (servers).
_Amy 8-Aug-12 1:08am    
Use server1.Database1.DBO.tbEmployee. As I told fully qualified...
Soft009 8-Aug-12 1:21am    
Thanks i'll try....
1)Linked server can used for connection purpose..
2)select * from [LocalTablename] as t1 where not exists (SELECT * FROM [Linkedservername].IAT.dbo.destinationtable as t2 where t1.Id=t2.Id)
above use for comapare local table and destination table.

3)select * from [Linkedserver].IAT.dbo.destinationtable it is use for see data for another instance data.
4)copy into temporary table .
Then you can do any operation on it.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900