23

Possible Duplicate:
Selecting data from two different servers in SQL Server

How can I join two tables, which are located two different SQL Server instances, in one query?

Community
  • 1
  • 1
Tarik
  • 79,711
  • 83
  • 236
  • 349

3 Answers3

22

The best way I can think of to accomplish this is via sp_addlinkedserver. You need to make sure that whatever account you use to add the link (via sp_addlinkedsrvlogin) has permissions to the table you're joining, but then once the link is established, you can call the server by name, i.e.:

SELECT *
FROM server1table
    INNER JOIN server2.database.dbo.server2table ON .....
Scott Arrington
  • 12,325
  • 3
  • 42
  • 54
9

You can create a linked server and reference the table in the other instance using its fully qualified Server.Catalog.Schema.Table name.

Restore the Data Dumps
  • 38,967
  • 12
  • 96
  • 122
3

If you are using SQL Server try Linked Server

Ralf de Kleine
  • 11,464
  • 5
  • 45
  • 87