Page 1 of 1

Copy record in the same table

Posted: Tue 14 Feb 2006 10:49
by Thomas J.
Hello, is it possible to make a copy of a record from table a and paste this record to the same table?
Or is the only solution by iterating over .Fields.Fields[]?

I thought something like this
TMyTable* table = ......;
// locate the record which has to be copied
table->LocateRecord(...);
// make a copy of the located record
table->CopyRecord();
// change few fields
table->FieldByName("d_created") = now();

table->Post();

Thanks for your help

Posted: Tue 14 Feb 2006 15:48
by GEswin
You can always use the Insert stament using a query/cmd..

Code: Select all

  INSERT INTO table (fields...) select fields.. from table where field = xxx

Posted: Tue 21 Feb 2006 08:45
by Thomas J.
This is not working due to the problem of PK.
I want to copy a record in the same table with exception of the PK. And if I execute the statement like you posted I get the error.
This is what I tried also and there is also exits another syntax, but this is not working too.

Posted: Tue 21 Feb 2006 13:37
by Antaeus
Try the same but don't forget to define your primary key as AUTO_INCREMENT and exclude exclude its field from list of fields you use in SELECT and INSERT statements.
Another way is copying field by field in a loop using MyTable or MyQuery.