Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's the most efficent way to copy record from one table to another?

Status
Not open for further replies.

safarijoe2000

Programmer
Jul 25, 2002
38
0
0
GB
I have 2 tables (Table1 & Table2).

Table1 is the old version of Table2.
I have added 3 new fields to Table2.

However, I need to copy all the records from Table1 to Table2 (regardless of the fact that Table1 doesn't have the 3 new fields that Table2 has).

Here's the kicker: the 2 tables reside in 2 different projects.

What is the most efficient way to copy all these records?

As always, I'd appreciate any help.
 
That is correct if you have the 2 tables in the same project. These 2 tables are in 2 different projects.

I was thinking about doing a:
COPY TO filename1 TYPE SDF

And then importing "filename1" to my existing project
IMPORT FROM filename1

However, the records don't align properly. Some data from some fields gets carried to the next fields, so even though the tables are almost mirror images, the data gets all mixed up.

Any ideas?
 
Tables is tables. No matter what project they're in. I guess I don't understand the problem. Are the tables different structures? Have different field names? Did you build them into an executable?

If they have the same structure except for the new ones:
USE Table1
COPY TO TempFile
USE Table2
APPEND FROM TempFile

-or-
If field names are different, but types are the same:
SELECT 0
USE Table1
SELECT 0
USE Table2

SELECT Table1
SCAN
SCATTER MEMVAR
SELECT Table2
APPEND BLANK
REPLACE Field1 WITH m.Table1Field1
REPLACE Field2 WITH m.Table1Field2
.
.
.
SELECT Table1 &&... not really needed
ENDSCAN

Dave S.
 
if youare talking about two different databases containers
dbc1.table1 and dbc2.table2 you cna still so as DSummZZZ said in the first post. make sure that you open the two databases and address the correct path to the two tables. if the two tables have the same name, then assign alias to them when opening

use drive:\path\table1 alias oldtable
use drive:\path\table2 alias newtable Attitude is Everything
 
If the records do not align or the field contents of the old table spill over on the new table, this sounds like you do not have the same field lengths, or you have inserted the new fields somewhere in the middle of the new table.

Assuming the field names are the same you can do as DSumZZ says as that requires a line of code for each field to make sure the data in inserted into the same field in the new table.

A better practice is to add your new fields at the end, and then when you do the APPEND FROM table1, one line of code is all that is required to move the data.

Another method is to COPY table1 to Table2, and then insert code modifies the structure of table2 to add the additional fields. This assumes there is not alreadey data in table2, however. if you craft the command table2 will be inserted into database 2 This method assums there are no joins in Database2

The copy command will preserve the indexes, whereas the append from won't, and will require you to have the indexes already set in table2.
 
create a remote view to the foreign table. from there on it's just as if the table was in your native database.
 
You do not need a remote view to look at another dbc, it is a large waste of overhead. Local views will do just fine or just open the table with a full reference including the dbc name and alias it if the table names are the same.

Sheesh, what a mountain out of a molehill.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top