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)));
}
}
}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.