Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
jchacko_rxsense
Contributor III
Contributor III

For... Next Looping in Qlik Sense

Hello,

I have a code

My_Table_Raw:
Load
          Chr(39) & Col1 & Chr(39),
          Chr(39) & Col2 & Chr(39),
          Chr(39) & Col3 & Chr(39)

;
Select Col1,Col2,Col3 from SQL_Server_Table;

My_Table:
NoConcatenate
Load
           *,
           '(' &   Col1   &   ','  &  Col2  &   ','   &   Col3   &  ')' as Col_Vals_Concat

resident My_Table_Raw;

num_rows =  NoOfRows('My_Table');

For  i   to   num_rows-1

    let Concat_Values = Peek('Col_Vals_Concat', $(i),'My_Table')

    SQL
     insert into table1 (Col1,Col2,Col3)
     Values
     $(Concat_Values)
     ;

next i
;

 

Suppose there are 10 rows. I am able to run the loop  5 times but at the 6th iteration it throws an error.

"The following error occurred:Connector reply error: SQL##f - SqlState: 42000, ErrorCode: 1003, ErrorMsg: SQL compilation error: syntax error line 16 at position 2 unexpected 'Next'."

Not sure why the error pops up as it ran 5 times before without error. Any suggestions.

Labels (3)
1 Reply
MendyS
Partner - Creator III
Partner - Creator III

Hi @jchacko_rxsense 

take a look at this article, 
its talks exactly about your problem.


Bitmetric Friday Qlik Test Prep - Week 6 - Looping tables - Solution | LinkedIn

 

if its help you to resolve the problem, please close the issue, thanks