Copy and paste record in one table

casio11casio11 Member Posts: 12
Hi,

I want to create function or report which copy and paste record, but in same table.
Example:
I have Table1 with key KEY001(auto-increment), and i want to copy rows KEY001,KEY002... and past in the end of the Table.

Best Answer

Answers

  • SowkarthikaSowkarthika Member Posts: 102
    You can create a function to copy a record. You can make use of COPY or TRANSFERFIELDS functions to copy record.
  • KishormKishorm Member Posts: 921
    As @Sowkarthika has stated above you can/should use the TRANSFERFIELDS function to copy the fields from one record to another. In addition to this you must set the key field to 0 before you call the INSERT method so that the next auto-increment value can be assigned.
  • TiwazTiwaz Member Posts: 98
    Well TRANSFERFIELDS won't work if he works in the same table since it transfers the fields depending on field ID.
    Not sure what you're trying to do.
    Do you want to find first few values and then to add them at the end of your table?
  • KishormKishorm Member Posts: 921
    Tiwaz wrote: »
    Well TRANSFERFIELDS won't work if he works in the same table since it transfers the fields depending on field ID.
    Not sure what you're trying to do.
    Do you want to find first few values and then to add them at the end of your table?

    Of course TRANSFERFIELDS will work in the same table, e.g....
    Customer1.TRANSFERFIELDS(Customer2);
    
    ...will work perfectly well where both Customer1 and Customer2 records are for Table 18 for example.
  • RockWithNAVRockWithNAV Member Posts: 1,139
    Go ahed with TRANSFERFIEDLS

    Write some code like like this
    Customer1.INIT;
    Customer1.TRANSFERFIELDS(Customer2);
    Customer1.INSERT;

    Customer 2 should hold all those entries which you want to copy.

    If the Key is Autoincrement then it will handle the Primary value itself you even dont have to worry on this.

  • RockWithNAVRockWithNAV Member Posts: 1,139
    Hi Mohana,

    Ya I agree that you need to write this piece of code or else you can set 0 as InitValue property but the point is I have had experienced a case where i dint need to do any of these things, seems magical but it do happened.

  • KishormKishorm Member Posts: 921
    My experience is that the AutoIncrement field does need to specifically be set to 0 prior to inserting the record as @mohana_cse06 has stated. The MSDN help also states that this should to be done ...

    https://msdn.microsoft.com/en-us/library/dd338603.aspx
    If you want to insert a record, be sure that the value in this field is blank before you insert the record. This is even more critical when you are using the SQL Server Option.
Sign In or Register to comment.