Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello All,
I'm trying to execute 10 sql queries in qlik sense which have same fields but different data but the output is showing same values for all the tables. Below is my script.
Table:
Load
Name,
sql_statement,
Product
from table;
Test:
load
' ' as Empty,
autogenerate 0;
For I=0 to Noofrows('Table')-1
let vName= peek('Name','$(i)','Table);
let vproduct = peek('Product','$(i)','Table);
let vSQL = peek('sql_statement','$(i)','Table);
let vSQL_Query= replace(replace(peek('sql_statement',0,'Table'),'Product','$(vproduct)'),'DB','$(vDB)');
LIB connect to '$(vConn)';
Concatenate(Test)
load
*,
'$(vName)' as Table_Name;
SQL $(vSQL_Query);
Next i
drop table Table;
I notice this row
let vSQL_Query= replace(replace(peek('sql_statement',0,'Table'),'Product','$(vproduct)'),'DB','$(vDB)');
Your peek are always looking at the same row, row 0. Maybe you need to use the variable i here as you do for the other peek statements.
let vSQL_Query= replace(replace(peek('sql_statement',$(i),'Table'),'Product','$(vproduct)'),'DB','$(vDB)');
I also notice that you loop is done on 'I' and not 'i' as expected in the peek statements. (But I assume that is just another spelling error)
Do you get an error message?
I would guess that you run into trouble on this line:
Concat(Test)
Try changing it to Concatenate (Test) instead.
Concatenate () is the correct function when concatenating data in a load. Concat() is used for aggregating a field inside an application.
Hi Vegar,
Sorry i have manually written the above script. Yes i used concatenate. The issue i see here is same sql is executing for all the names (Table Name). So the output is showing same results for all these 10 tables.
Thanks
I notice this row
let vSQL_Query= replace(replace(peek('sql_statement',0,'Table'),'Product','$(vproduct)'),'DB','$(vDB)');
Your peek are always looking at the same row, row 0. Maybe you need to use the variable i here as you do for the other peek statements.
let vSQL_Query= replace(replace(peek('sql_statement',$(i),'Table'),'Product','$(vproduct)'),'DB','$(vDB)');
I also notice that you loop is done on 'I' and not 'i' as expected in the peek statements. (But I assume that is just another spelling error)
@Vegar It worked. Thanks a lot. 🙂