
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
SQL Query From Different Databases
I want to write a single SQL query that pulls data in from two different servers/databases rather than doing individual queries and joining or concatenating the results. Is this possible? I don't see how to have two different connectionsactive in the script at the same time.
Example:
SQL Select tableA.*, tableB.*
from Server1.MyDatabase.tableA as tableA, Server2.MyDatabase.tableB as tableB
where tableA.Key = tableB.Key
- Tags:
- connection
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks guys. I know all the standard ways to do it, which were the ones I wanted to avoid. So I guess the simple answer is No, you can't run a single query against multiple data sources at the same time.
Thanks anyway!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have only one connection on the same time. You can load the first table into the memory,switch the connection,load the second table and combinate with the first. Maybe drop the first finaly.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Stepping out from QV.
If you are reading data from SQL server then you can use the Linked server technology.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The easiest is to make a loop with a change of connection between each SQL Statement
For I=1 to 2
IF I= 1 THEN Connect xxxxxxxxx END IF
IF I=2 THEN Connect xxxxxxx END IF
SQL_TABLE:
SQL Select tableA.*, tableB.*
from Server1.MyDatabase.tableA as tableA, Server2.MyDatabase.tableB as tableB
where tableA.Key = tableB.Key
next i
Something like that...
Or you copy twice the SQL Statement with a connect between each of them
CONNECT TO xxxxxx
MyTable:
SQL xxxxxxx
CONNECT TO yyyyy
Mytable:
SQL xxxxxxx
As SQL are equals, everything will be in the same table.
rgds


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Other Simple Method: by
You can load resident 2 table and take it join in Edit script 's Qlikview
Ex
1.
Connect to Server1.MyDatabase
tblTableA:
Load
SQL select tableA.*
From Server1.MyDatabase.tableA as tableA
2.
Connect to Server1.MyDatabase
tblTableB:
Load
SQL select tableB.*
From Server2.MyDatabase.tableB as tableB

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks guys. I know all the standard ways to do it, which were the ones I wanted to avoid. So I guess the simple answer is No, you can't run a single query against multiple data sources at the same time.
Thanks anyway!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just being curious here. Why do you want to avoid the standard ways? Any specific benefits?
/F

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It was from one of our DBAs. He lives in the MS SQL Server Stored Procedure world and was looking to leverage his SQL writing skills more than conform to QlikView scripting. LOL

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hehe. LOL.
I was investigating different scenarios in my head why it would be a good idea but never thought of the most obvious one: because the developer wants to... 😄
