How can I copy a record from one table to another

How can I copy a record from one table to another

Postby el_ade » Thu 07 Apr 2005 12:36

I have a table where the users send reviews, this review is stored in a tempo table, when I aprove the review I need to copy the record data in table1 (tempo) to table2.

I´m doing this with delphi, I have tryed to use the TmyScript component but I can´t make the recovering of the fields content.

¿Can somebody help me?
el_ade
 

Postby Ikar » Thu 07 Apr 2005 13:10

It would be correct to perform this task at the server using INSERT ... SELECT statement
Ikar
 
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Postby Guest » Thu 07 Apr 2005 13:23

I´m trying to use the following code, and I supose it will work, but I wonder if ther isn´t an easyer way to do the same.

MyCommand1.SQL.Text := 'insert into reviews values (NULL,'''+
QReviews_Add.Fieldbyname('date').AsString +''','''+
QReviews_Add.FieldByName('title').AsString +''','''+
QReviews_Add.FieldByName('text').AsString +''','''+
QReviews_Add.FieldByName('reviewer').AsString +''','''+
QReviews_Add.FieldByName('email').AsString +''','''+
QReviews_Add.FieldByName('score').AsString +''','''+
'1'','''+
QReviews_Add.FieldByName('url').AsString +''','''+
'1'','''+
QReviews_Add.FieldByName('rlanguage').AsString+

''')';
Memo1.Text := MyCommand1.SQL.Text;
MyCommand1.Execute;
Guest
 

Postby Ikar » Fri 08 Apr 2005 07:24

After that as QReviews.Post was executed you should execute the next:

MyCommand1.SQL.Text := 'insert into reviews (date, title, text, reviewer, email, score, url, rlanguage, ...)SELECT date, title, text, reviewer, email, score, url, rlanguage, 1, 1 FROM qreviews';
MyCommand1.Execute;
Ikar
 
Posts: 1693
Joined: Thu 28 Oct 2004 13:56


Return to MySQL Data Access Components