Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Iterate over table values and construct strings?

I have a set of key values in a qlikview table:

keytable:
key1, key2, key3, ...

I want to iterate through these, construct SQL statements, and run the SQL statements and append the results into a new table.

for each key in keytable

LET SQL = "SELECT * FROM table WHERE key=", key, ";"
LOAD SQL;

Has anyone done something like this before? Any recommendations for how to do this?

1 Solution

Accepted Solutions
johnw
Champion III
Champion III

Maybe something along these lines, but I'm rather unclear on the DETAILS of what you're trying to do... is "key1" a value or a field in keytable? Is ", key, " an actual value in your source table, or am I supposed to be substituting something there? Sure doesn't look like a value, but no idea what I'd be substituting. Blah blah blah other questions blah blah blah.

[New Table]:
LOAD *; SQL SELECT * FROM table WHERE $(=peek('key',I,'keytable')) = ", key, ";

FOR I = 0 TO noofrows('keytable')-1
CONCATENATE ([New Table])
LOAD *; SQL SELECT * FROM table WHERE $(=peek('key',I,'keytable')) = ", key, ";
NEXT I

View solution in original post

3 Replies
johnw
Champion III
Champion III

Maybe something along these lines, but I'm rather unclear on the DETAILS of what you're trying to do... is "key1" a value or a field in keytable? Is ", key, " an actual value in your source table, or am I supposed to be substituting something there? Sure doesn't look like a value, but no idea what I'd be substituting. Blah blah blah other questions blah blah blah.

[New Table]:
LOAD *; SQL SELECT * FROM table WHERE $(=peek('key',I,'keytable')) = ", key, ";

FOR I = 0 TO noofrows('keytable')-1
CONCATENATE ([New Table])
LOAD *; SQL SELECT * FROM table WHERE $(=peek('key',I,'keytable')) = ", key, ";
NEXT I

Not applicable
Author

Thanks John. That's perfect!

Now I don't suppose you would be able to show me how you could do this with a try...catch equivalent around the SELECT block? In some cases, I get an error message from SELECT statement, and I just want to skip those.

I read through this question, but it isn't clear to me:

http://community.qlik.com/forums/p/16288/63539.aspx

johnw
Champion III
Champion III

Sorry, I haven't played with the error mode, so I'd just be reading other forum posts to figure it out too. 🙂