Ok, more details :
The while clause will keep on loading a record while the condition is false. In your example, the first line of table Data will be loaded, IterNo (for iteration) will be 1, so StartDate-IterNo+1 will be start date, and as this is below EndDate, this first record will be loaded a second time, with IterNo = 2, and so on until EndDate. The second record of table date will be processed in the same way.
To better understand this try a simple script like :
load * inline [
StartDate, EndDate, id
1, 5, a
3, 8, b
2, 4, c
12, 14, d
LOAD DISTINCT (StartDate+IterNo()-1) AS date, id as id2, IterNo() as IterNo, rowNo() as rowNo
Hi Attitude ,
This function is only meaningful if used together with a while clause. IterNo( ) returns an integer indicating for which time one single record is evaluated in a load statement with a while clause. The first iteration has number 1.
For Example Your Fields Havng the example data:
for the firat iteration ( loading first row), the ItrNo() returns 1, for the second row itrNo() returns 2.. and so on..
so, DATE(StartDate+IterNo()-1) AS date
means DATE(StartDate+1-1) AS date --> next date.. finally the reulatant table like this...
StartDate EndDate DATE(StartDate+1-1) <= EndDate Date
1/1/2011 3/1/2011 DATE(1/1/2011 +1-1) 1/1/2011 <=3/1/2011 true 1/1/2011
2/1/2011 4/1/2011 DATE(2/1/2011 +2-1) 3/1/2011<=4/1/2011 true 3/1/2011
3/1/2011 4/1/2011 DATE(3/1/2011 +3-1) 5/1/2011<= 4/1/2011 false -
Replying late to this post. IterNo gets the number of iterations performed so far.
By this def, it makes sense that it can only be used with some loop.
ex. AUTOGENERATE (1) WHILE $(vMinDate) + IterNo() - 1 <= $(vMaxDate)
We can use the above logic to generate date ranges of size one day starting
from vMinDate to vMaxDate (variables). Btw, QV stores dates as number of days.
It seems to me that QV stores the number of iterations somewhere and gets
that value from IterNo().
So, the above loop is like this in any programming language -
int count = 0;// like iterNo
int vMinDate = 11; // say 11th day from Jan 1.
int vMaxDate = 15
while( (vMinDate + count) < vMaxDate )
starts = vMinDate
ends = vMinDate + 1
count = count + 1;