how to get data from 2 database

Solutions on MaxInterview for how to get data from 2 database by the best coders in the world

showing results for - "how to get data from 2 database"
Janie
27 Jun 2016
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