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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to create a loop in SQL Statement

I have a SQL Load statement in QV which queries a very large table. It's so large that I need to load the days rows by breaking up the SQL into hourly increments. Is there a way to create a looping staement which will allow me to write one SQL statement but loops through the full day?

Labels (1)
2 Replies
eduardo_sommer
Partner - Specialist
Partner - Specialist

Hi John,

You can create a subroutine with the Load and Select using a where clause that limits the load to one hour. The syntax will be something like

     WHERe HourInDB = $(HourInParameter)

This HourInParameter can be a parameter from the subroutine or a control variable in a For Each command.

The structure might be something like:

Sub LoadSub (HourInParameter)

Table:

Load

     .

     .

     .

;

SQL SELECT

     .

     .

     .

FROM DB

WHERE HourInBD = $(HourInParameter);

End Sub

Call LoadSub(1)

Call LoadSub(2)

.

.

.

Call LoadSub(23)

Or a loop for the 24 hours of the day

I hope this have been helpful.

Eduardo

maxgro
MVP
MVP

something like (replace my load from qvd with your sql from database)

for  i=1  to 24

     table:

     load *

     from tablemap.qvd (qvd)

     where hour = '$(i)';

next i;