Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
m_perreault
Creator III
Creator III

Looping Through all Tables in existing Data Model

Hi All,

I want to loop through all of the tables in my data model and store them down into QVDs. I have created the below script to test but it keeps failing.  For whatever reason once it gets to the third table the Tables variable returns null().  Any idea why this isnt working.  I know I could just write store statements after each load but I have a use case for this and cant understand why its not working.

 

A:
Load * Inline
[A];

NoConcatenate
B:
Load * Inline
[B];
NoConcatenate

C:
Load * Inline
[C];

NoConcatenate
[D]:
Load * Inline
[D];

 

let vTables = NoOfTables();

Let i = 0;

Do While i < vTables

Let Table = TableName(i);

NoConcatenate
[Temp]:
Load *
Resident [$(Table)];

Store Temp into [lib://Test\$(Table).txt](txt);
Drop Table $(Table);
Drop Table Temp;
i = i + 1;

Loop;

Exit script

 

Thanks!

Mark

Labels (2)
1 Solution

Accepted Solutions
m_perreault
Creator III
Creator III
Author

Ah I got it.

Since I was dropping tables in the Loop by doing i + 1 I was skipping tables.

 

Using the below works

 

Let i = 0;

Do While i < NoOfTables()

Let Table = TableName(i);

NoConcatenate
[Temp]:
Load *
Resident [$(Table)];

Store Temp into [lib://Test\$(Table).txt](txt);
Drop Table [$(Table)];
Drop Table Temp;
;

Loop;

Exit script

 

 

View solution in original post

3 Replies
m_perreault
Creator III
Creator III
Author

Ah I got it.

Since I was dropping tables in the Loop by doing i + 1 I was skipping tables.

 

Using the below works

 

Let i = 0;

Do While i < NoOfTables()

Let Table = TableName(i);

NoConcatenate
[Temp]:
Load *
Resident [$(Table)];

Store Temp into [lib://Test\$(Table).txt](txt);
Drop Table [$(Table)];
Drop Table Temp;
;

Loop;

Exit script

 

 

m_perreault
Creator III
Creator III
Author

Further more there is no reason to Load the tables again just the below is sufficient

 

Let i = 0;

Do While i < NoOfTables()

Let Table = TableName(i);

Store [$(Table)] into [lib://Test\$(Table).txt](txt);
Drop Table [$(Table)];
;

Loop;

steasy
Contributor III
Contributor III

Two years later and glad that you documented your outcome 😊