on 01-12-2015 8:39 AM
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
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,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
8 | |
7 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.