Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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!

View solution in original post

8 Replies
Not applicable
Author

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.

Not applicable
Author

Stepping out from QV.

If you are reading data from SQL server then you can use the Linked server technology.

http://msdn.microsoft.com/en-us/library/ms188279.aspx

Not applicable
Author

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

thanomjit
Partner - Contributor II

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

Anonymous
Not applicable
Author

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!

Not applicable
Author

Just being curious here. Why do you want to avoid the standard ways? Any specific benefits?

/F

Anonymous
Not applicable
Author

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

Not applicable
Author

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... 😄