Can any one suggest how to do this requirement.
Can you explain the requirement further? It looks like you want to load a different number of days based on a variable.
Something like this maybe.
if nooffailures=0 then
where calendarkey<today()+1 and calendarkey>$(vDateCount);
Update: Had to edit for the variable.
Retrieving data ...