``````for (int I=-1; I<30; I++)
{
for (int J=0; J<30; J++)
{
for(int K=1; K<30; K++)
{
SELECT rowid,Month, Day, Advice from MainCategory where Month= 'May ' and Day in ((cast(strftime('%d',date('now','+(I) day')) as Integer)),(cast(strftime('%d',date('now','+(J) day')) as Integer)),(cast(strftime('%d',date('now','+(K) day')) as Integer)));
}
}
}``````

And for the same reason how to decrement in this query

``````for (int I=-1; I<30; I--)
{
for (int J=0; J<30; J--)
{
for(int K=1; K<30; K--)
{
SELECT rowid,Month, Day, Advice from MainCategory where Month= 'May ' and Day in ((cast(strftime('%d',date('now','(I) day')) as Integer)),(cast(strftime('%d',date('now','(J) day')) as Integer)),(cast(strftime('%d',date('now','(K) day')) as Integer)));
}
}
}``````
3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by ch_shoukat222

I'm not sure exactly what you're trying to do, but your second block of code will create an endless loop because subtracting from -1...it will always be < 30. I would recommend using a stored proc, passing in all of your values for I, J, K and another value for increasing or decreasing .... i.e. usp_GetAdvice I_value, J_value, K_value, 'A' (or 'S')....then let your SQL engine do the bulk of the work and return you one full dataset.

I know you're using C#, but what SQL backend are you using?

Also, something else you may want to consider is a variable for your "Month" value....you have hard-coded WHERE Month = 'May '.....that might cause problems if you want this to be dynamic.

Edited by bhartman21: n/a

what you actually want?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.