cancel
Showing results for 
Search instead for 
Did you mean: 

How to use 'UNION' between two different databaseservers

Former Member
0 Kudos

Hello,

Could someone help me out. I am trying to find out if and how to use 'UNION' between two different databaseservers.

We have 2 different queries, each queries on a different database; one MySQL the other MSSQL.

Could someone tell me how to use 'UNION' between thes 2 queries?

Thanks in advance,

Samir Benalla

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

Hello

You may use openrowset statement, (OPENROWSET (Transact-SQL))., but before you use this, you must configure your server

sample:


SELECT a.*

FROM OPENROWSET('SQLNCLI', 'Server=Seattle1;Trusted_Connection=yes;',

     'SELECT GroupName, Name, DepartmentID

      FROM AdventureWorks2012.HumanResources.Department

      ORDER BY GroupName, Name') AS a

UNION

     SELECT GroupName, Name, DepartmentID

      FROM AdventureWorks2012.HumanResources.Department

      ORDER BY GroupName, Name

With this you can define a connection using native client to server Seattle1, and execute a query there, The results will be spooled on your server.

Connectionstring

Server=[SERVER_NAME];datasource=[YOUR DATABASE NAME];user_id=sa;password=sapassword'

if you use FQDN on your Query, than the datasource parameter in connection string can be letf out.

Regards

János.

take care of performance, it can be very slow,