Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

loop inside loop

Hello, I've just started working with QlikView and I would appreciate some help...

I have to execute a procedure against a SQL database for each row in a spreadsheet. My qvw script already has a loop to do this, and it is working well. The problem is, I need a second loop so I can run the existing one for different sets of dates (initial and final date variables).                      

The script goes like this:

LET InitialDate = Date(Today()-7 , 'YYYYMMDD');

LET FinalDate   = Date(Today()-7 , 'YYYYMMDD');

Base:

LOAD    cdCompanyCode

             ,cdProductionType

FROM $(Industry)\FBPD316_Comparison.xls (biff, embedded labels, table is CompanyProductionType$) ;

LET nrRows = NoOfRows('Base');

LET iCounter = 0;

   

DO WHILE iCounter < nrRows

    LET AncdCompanyQV           = Peek('cdCompanyCode', $(iCounter), 'Base');

    LET AncdProductionType      = Peek('cdProductionType', $(iCounter), 'Base');

    SET AdInitial               = $(InitialDate);

    SET AdFinal                 = $(FinalDate);

  

    FactTable:

LOAD *

     , date(Date#($(AdInitial),'YYYYMMDD'),'DD/MM/YYYY')    AS dInitial

     , date(Date#($(AdFinal),'YYYYMMDD'),'DD/MM/YYYY')    AS dFinal;

   

SQL EXECUTE dbo.SQL_Procedure $(AncdCompanyQV)                             

                                     , '$(AdInitial)'         

                                     , '$(AdFinal)'        

                                     , $(AncdProductionType)     

    

LET iCounter = iCounter + 1;

LOOP

Now I want this loop to be automatically executed for Today()-6, Today()-5, Today()-4 and so on, without having to change it manually.

How would that work?

1 Reply
marcus_sommer

You could just put a loop around your other statements/loops like:

for i = 0 to 7

     LET InitialDate = Date(Today()-$(i) , 'YYYYMMDD');

     LET FinalDate   = Date(Today()-$(i) , 'YYYYMMDD');

     ....

next

- Marcus