Skip to Content
avatar image
Former Member

How to use 'UNION' between two different databaseservers

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Jan 12, 2015 at 10:25 PM

    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,

    Add comment
    10|10000 characters needed characters exceeded