1-- Fetch data from the other database server
2SELECT *
3INTO #myTempTable
4FROM OPENQUERY([DB2], 'SELECT * FROM [MyDatabaseOnDB2].[dbo].[MyOtherTable]')
5
6-- Now I can join my temp table to see the data
7SELECT * FROM [MyDatabaseOnDB1].[dbo].[MyTable] tab1
8 INNER JOIN #myTempTable tab2 ON tab1.ID = tab2.ID