Is there a way to execute union of 2 SQL queries from different SQL Servers as shown below in my query?
Select * from table1 (server 1)
union
Select * from table1 (server 2)
Is there a way to execute union of 2 SQL queries from different SQL Servers as shown below in my query?
Select * from table1 (server 1)
union
Select * from table1 (server 2)
You need to create the linked server so you have to access of that server after that You can try this way to call and execute the query.
A linked server allows for access to distributed, heterogeneous queries against OLE DB data sources. After a linked server is created, distributed queries can be run against this server, and queries can join tables from more than one data source. If the linked server is defined as an instance of SQL Server, remote stored procedures can be executed.
Select * from <ServerName>.<databaseName>.<SchemaName>.<Table1>
Here is the official documentation to configure the link server.
Look into linked servers first.
Then write your query with aliases, like this:
SELECT r.[Project_ID], a.[Name]
FROM [LocalDatabase].[dbo].[Record] r inner join
[LinkedServer].[Reporting].[dbo].[Active] a
ON r.[Project_ID] = a.[Delivery_Number];