Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Pull data from multiple databases

I’m just starting out with Qlikview and trying to load our data from our financial application.  We currently have about 900 databases in this system each with the exact same schema.  Somehow I need to use a statement like the one below and loop through each database replacing D182 with a database number.  Any ideas if this is possible and how it can be done?

APPYDET:

LOAD

      trx_ctrl_num as _trx_ctrl_num_py,

      sequence_id as sequence_id_py,

      apply_to_num as _trx_ctrl_num,

      amt_applied;

SQL select

      trx_ctrl_num,

      sequence_id,

      apply_to_num,

      amt_applied

from D182.dbo.appydet

1 Solution

Accepted Solutions
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Try something like below.

     Min_Max:

     Select Min,Max from database.table1

     let vMin = peek('Min',0,'Min_Max');

     let vMax= peek('Max',0,'Min_Max');

for idx = $(vMin) to $(vMax)

let dbnum = 'D' & text(idx) & '.dbo.mytable' // format number with 3 digit if you need

...

select ...

...

from $(dbnum)

next

    

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!

View solution in original post

3 Replies
alexandros17
Partner - Champion III
Partner - Champion III

for idx = 1 to 900

let dbnum = 'D' & text(idx) & '.dbo.mytable' // format number with 3 digit if you need

...

select ...

...

from $(dbnum)

next

Anonymous
Not applicable
Author

This works perfect when hard coding 1 to 900.  How can I set db_num equal to a value that is returned by a SQL statement?

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Try something like below.

     Min_Max:

     Select Min,Max from database.table1

     let vMin = peek('Min',0,'Min_Max');

     let vMax= peek('Max',0,'Min_Max');

for idx = $(vMin) to $(vMax)

let dbnum = 'D' & text(idx) & '.dbo.mytable' // format number with 3 digit if you need

...

select ...

...

from $(dbnum)

next

    

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!