Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to join 2 tables from different servers?

Author  Topic 

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2011-11-22 : 03:29:25
Hi,

I would like to join two tables in two different servers. Is there a way to do it?

Best Regards.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-22 : 03:44:26
yep.
add second server as a linked server to first using sp_addlinkedserver and then use like


select columns..
from table1
inner join [linkedservername].dbname.dbo.table2
on...


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2011-11-22 : 03:49:47
Hi,
If it is NOT linked server, is there a way to join?

Best regards.
Go to Top of Page

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2011-11-22 : 03:51:22
I guess I found out

ServerName.DbName.dbo.Table
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-22 : 04:13:49
quote:
Originally posted by raysefo

I guess I found out

ServerName.DbName.dbo.Table


Unless you add server as a linked server you wont be able to use four part naming convention like above

If you dont have linked server setup, then only other way is to use OPENROWSET

http://msdn.microsoft.com/en-us/library/ms190312.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jassi.singh
Posting Yak Master

122 Posts

Posted - 2011-11-22 : 04:59:13
you need to create linked server to access objects from different server
check this
http://www.techrepublic.com/blog/datacenter/how-do-i-query-foreign-data-using-sql-servers-linked-servers/133
Go to Top of Page
   

- Advertisement -