copy of data from one table to another table

surisuri Member Posts: 123
hi good evening one and all

i have created two tables
table 1 and table 2
table 1 consists of fields
no name designation
1 bbb kkkk
2 nnn mmm
3 kkk llllll

table 2 consists of fields
no name designation

i want to copy data from table 1 to table 2

i have written code like this as shown below


table1.RESET;
IF table1.FINDFIRST THEN
REPEAT
INIT;

no :=table1.no;
name :=table1.name;
designation :=table.designatio;
INSERT;
UNTIL table1.NEXT=0;

but it was not inserting any values into the table2
can any one can give suggetsion
thank you

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Manually copy rows in table 1 and paste in table 2.

    Where did you write above code?
  • surisuri Member Posts: 123
    hi mohana thanks for giving reply....i have tried in the below manner.
    actually one thing i dont know where to write the code..can you send any pdf file regarding this triggers,,,,when and where to write the code...it will be helpful to me ...thank you
    i have tried in on after get record in reports(but the data was not inserted)
    i have tried in on validate of no field in table 2(but the data was not inserted)
    i have tried in on insert in table 2(but the data was not inserted)
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Here is the Help link
    http://msdn.microsoft.com/en-us/library/dd301068.aspx

    You need to take Table1 as dataitem and check whether record is available in table2, if not insert..
  • surisuri Member Posts: 123
    ya mohana sir

    i have tried the below code in
    predataitem() with processing only yes
    testing.RESET;
    IF testing.FINDFIRST THEN REPEAT
    test9.INIT;
    test9.no :=testing.no;
    test9.designation:=testing.designation;
    test9.INSERT;
    UNTIL testing.NEXT=0;

    it was working fine
    thanks for your reply

    can you share me the pdf file linc..please
  • ramsay18477ramsay18477 Member Posts: 52
    Why don't you write the copying code in the loop in the 'OnAfterGetRecord()' trigger of the report ?

    If you want to copy the table as it is, you can also use the 'TRANSFERFIELDS' function in the 'OnAfterGetRecord()' trigger of the report with the following code :
    test9.transferfields(test);
    
    Thanks & Best Regards,

    Ram.
  • colingbradleycolingbradley Member Posts: 162
    In case you need to add fields from one table to another where the target has a different key, you will need to do something like this:

    SalesInvHeader does not have a Document Type but HeaderLog does.
    HeaderLog is otherwise identical.
    Option 0 = Invoice

    SalesInvHeader.GET("No.");
    IF NOT HeaderLog.GET(0,SalesInvHeader."No.") THEN BEGIN
    HeaderLog.INIT;
    HeaderLog."Document Type" := 0;
    HeaderLog."No." := SalesInvHeader."No.";
    HeaderLog.INSERT;
    HeaderLog.TRANSFERFIELDS(SalesInvHeader,FALSE);
    HeaderLog.MODIFY;
    END;

    If you only need a subset of the SalesInvHeader transferred to HeaderLog, remove the unwanted fields in HeaderLog.
    Experience is what you get when you hoped to get money
Sign In or Register to comment.