Hello, im writing a C program that needs to get a value from my database and put it into a temporary table.

so far i can get the value from the database and insert it into my temp table.
if i fill in the right value in the where clause
What i want is...a loop that gets the value from the database 1 by 1 and inserts it into the temp table. but when the loop is done and starts over for the next value in the database it should overwrite the previous value inserted into the temp table.
This is my code, what its bout....i hope it makes some sense

//get data from table insert into temp table
hdl=mapi_query(dbh, "Select * from data");

number = mapi_fetch_field(hdl, 0);
printf("%s\n", number);
hdl = mapi_query(dbh, "INSERT INTO tempdata Select name from product where productid = 'number'");
if (mapi_error(dbh))
	hdl = mapi_query(dbh, "Select * from tempdata");
	while (mapi_fetch_row(hdl))
		result = mapi_fetch_field(hdl, 0);
		printf("%s\n", result);

i have tried to run it with one value from the database before i will try it with all values.
The program fails at "Insert into" ... it connects to the database creates the temp table...gets the first value from the table and prints in out on the screen...but fails to insert it into the temp table.

My question is how can i use the value that i got from the table and use it as a parameter in my where clause when doing "insert into temp table"??
What am i doing wrong??

Greetings jenny

5 Years
Discussion Span
Last Post by jenny666

Im not updating a record in my table....im inserting one.
if i do

hdl = mapi_query(dbh, "INSERT INTO tempdata Select name from product where productid = '5'");

it works fine..
but i want the where clause to by dymanic...my program has to run on its own getting the value and putting it into the temp table

This question has already been answered. 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.