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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
hopkinsc
Partner - Specialist III
Partner - Specialist III

Help with Loop

Hi all,

i am currently implementing an incremental load into an existing extract script.

here is a brief description on how my client wants it to work.

an admin user would update a field in the db with the amount of previous years to go back to extract.

Transaction_Years = 2

so far i have added a variable for the max year (taken from the list of distinct years in the db and a variable for the Transaction_Year that has been entered by the admin person.

vMaxYear = 2016

vTransaction_Year = 2

so what i want is to run a loop which loads all data for those years (2014,2015,2016) and stores each year into its own QVD.

apologies but i can't get my head around how to do this.

can anyone help please?

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

Something like:

//Create the QVDs

For i = (vMaxYear - vTransaction_Year + 1) To vMaxYear

  Data:

  SQL SELECT *

  FROM SourceTable

  WHERE Year = $(i);

  STORE Data into (qvd);

  DROP Table Data;

Next

Adjust the SQL SELECT and the QVD file name and path to match your requirements

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

3 Replies
Digvijay_Singh

Something like -

For each vYear in $(vMaxYear),$(vMaxYear-1),$(vMaxYear-2)

$(vYear)QVD:

Select ....

From DB

Where (Year,vYear)

Store $(vYear)QVD into Path/$(vYear)QVD

Next

Just an idea, it would need improvement to make it work

jonathandienst
Partner - Champion III
Partner - Champion III

Something like:

//Create the QVDs

For i = (vMaxYear - vTransaction_Year + 1) To vMaxYear

  Data:

  SQL SELECT *

  FROM SourceTable

  WHERE Year = $(i);

  STORE Data into (qvd);

  DROP Table Data;

Next

Adjust the SQL SELECT and the QVD file name and path to match your requirements

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
hopkinsc
Partner - Specialist III
Partner - Specialist III
Author

Thanks Jonathan, thats exactly what i needed.