Qlik Community

QlikView Connectors

Announcements
Announcement: We have made updates to resolve a Page Not Found error. If you still get this error, please let us know in the Community Corner.
Sa20
New Contributor II

Connect multiple databases sql

Please how can i connect multiple databases sql to analyze it as a single database in qlikView ?

5 Solutions

Accepted Solutions
Highlighted
shiveshsingh
Honored Contributor

Re: Connect multiple databases sql

You can create multiple connection strings and import data in qlikview.

After that, you can create single model as per your requirement.

Re: Connect multiple databases sql

Hi, you can store connection string in txt, and use a for each bucle to connect to each one to retrieve data, ie, assuming that all databases have the same tables:
for each table in 'table1','table2','table3' //fill with table names
for each connection in 'Connection1','Connection2','Connection3' //fill with txt names of connection strings
$(Include=path_to_connections\$(connection).txt); //this loads the connection
// Retrieve data from all connections
[$(table)]:
LOAD '$(connection)' as connection,
*
from [$(table)];
next
// store joined data into a qvd, this qvd will be readed by the app to load the data
Store [$(table)] into [Path_to _qvds_folder\$(table).qvd];
Drop [$(table)];
next

MVP
MVP

Re: Connect multiple databases sql

Follow this pattern:

  1. Connection for first database
  2. Load whatever data required from first database
  3. Open connection for next database (this will implicitly disconnect the first)
  4. Load whatever data required from second database (and concatenate or join to the earlier tables as required)
  5. Open connection to third database
  6. Etc Etc

The data from all the sources will be loaded into a single QVW file for analysis.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Sa20
New Contributor II

Re: Connect multiple databases sql

But databases do not have the same tables

Re: Connect multiple databases sql

You can create different variables to store table names:
SET vTablesConnection1 = 'Table1_Conn1', 'Table2_Conn1';
SET vTablesConnection2 = 'Table1_Conn2', 'Table2_Conn2';

for numberOfConnection=1 to 2
for each table in $(vTablesConnection$(numberOfConnection))
...
Next
5 Replies
Highlighted
shiveshsingh
Honored Contributor

Re: Connect multiple databases sql

You can create multiple connection strings and import data in qlikview.

After that, you can create single model as per your requirement.

Re: Connect multiple databases sql

Hi, you can store connection string in txt, and use a for each bucle to connect to each one to retrieve data, ie, assuming that all databases have the same tables:
for each table in 'table1','table2','table3' //fill with table names
for each connection in 'Connection1','Connection2','Connection3' //fill with txt names of connection strings
$(Include=path_to_connections\$(connection).txt); //this loads the connection
// Retrieve data from all connections
[$(table)]:
LOAD '$(connection)' as connection,
*
from [$(table)];
next
// store joined data into a qvd, this qvd will be readed by the app to load the data
Store [$(table)] into [Path_to _qvds_folder\$(table).qvd];
Drop [$(table)];
next

MVP
MVP

Re: Connect multiple databases sql

Follow this pattern:

  1. Connection for first database
  2. Load whatever data required from first database
  3. Open connection for next database (this will implicitly disconnect the first)
  4. Load whatever data required from second database (and concatenate or join to the earlier tables as required)
  5. Open connection to third database
  6. Etc Etc

The data from all the sources will be loaded into a single QVW file for analysis.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Sa20
New Contributor II

Re: Connect multiple databases sql

But databases do not have the same tables

Re: Connect multiple databases sql

You can create different variables to store table names:
SET vTablesConnection1 = 'Table1_Conn1', 'Table2_Conn1';
SET vTablesConnection2 = 'Table1_Conn2', 'Table2_Conn2';

for numberOfConnection=1 to 2
for each table in $(vTablesConnection$(numberOfConnection))
...
Next