dyanamic variable in embedded SQL in for loop in C
Date: Thu, 08 Jul 1999 16:07:09 GMT
Message-ID: <7m2ib3$fb4$1_at_nnrp1.deja.com>
Here's what I'm doing right now:
//12 months ago
EXEC SQL select count(*) into :a12
from sorted
where rid=:rid AND
ddate between last_day(add_months(SysDate, -13)) + 1 AND
last_day(add_months(SysDate, -12)) + 1;
//11 months ago
EXEC SQL select count(*) into :a11
from sorted
where rid=:rid AND
ddate between last_day(add_months(SysDate, -12)) + 1 AND
last_day(add_months(SysDate, -11)) + 1;
and so on, for the last 12 months. This gives me the number of lines in the table sorted for a certain rid. What I want to do is put this in a for loop so that I don't have to have 12 of them in my program. At the end of the for loop though, I need 12 seperate variables so that I can use them to output a graph onto the web page. I also need to keep track of which variable is the max out of all twelve. This is another reason why I need the for loop. The dynamic variable can be anything, char, int, whatever, I just need to know what it is so I can use it later on. I want it to theoretically look like this.
int max, i;
max=0;
for (i=13, i<=1, i--)
{EXEC SQL select count(*) into :(dynamic variable)
from sorted
where rid=:rid AND
ddate between last_day(add_months(SysDate, -:i)) + 1 AND
last_day(add_months(SysDate, -(:i-1))) + 1;
if (dynamic variable)>max max=dynamic variable; }
I'm trying this right now just to print them#include <stdio.h> #include <string.h>
int main()
{
int i;
char *a[12] =
{"a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","a10","a11"};
for (i=13; i<=1; i--)
printf("%s\n", a[i-1]);
return 0; }
but its not printing the variable.
Any ideas???
Thanks
James Thomson
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Received on Thu Jul 08 1999 - 18:07:09 CEST