SQL statement to select from 2 different tables, from two different databases (same server)

后端 未结 3 1388
难免孤独
难免孤独 2021-01-21 00:38

How do I select from multiple tables in different databases on the same server?

Also, Is there a way to have an identifying marker so I could see where the results came

3条回答
  •  旧巷少年郎
    2021-01-21 00:58

    try this: SELECT * FROM OPENROWSET('SQLNCLI', 'Server=YOUR SERVER;Trusted_Connection=yes;','SELECT * FROM Table1') AS a UNION SELECT * FROM OPENROWSET('SQLNCLI', 'Server=ANOTHER SERVER;Trusted_Connection=yes;','SELECT * FROM Table1') AS a

提交回复
热议问题