Focal Point
Combine two tables

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/1441088331

July 28, 2005, 06:28 AM
<Faisal I Rathor>
Combine two tables
I have two tables in SQL server, they both have one field in common. I want to fetch some fields from one table and some other fields from other table on the bases of common field and save the output to third table. I want to do this in Maintain toll.
Anyone assist me how I can do that?
July 28, 2005, 12:02 PM
Maintain Wizard
The easiest way to do this, is to create 3 stacks. The first one retrieves data from file one, the second one from file two, and then add them to the third stack and save them to the database.

Assume
File1 has fieldA, field1, field2, field3.
File2 has fieldA, field4, field5, field6
File3 has fieldA and fields 1 - 6

Then

MAINTAIN FILE FILE1 AND FILE2 AND FILE3
INFER FILE3.fieldA into STACK3
FOR ALL NEXT FILE1.fieldA into STACK1
WHERE FILE1.fieldA = val -* criteria goes here
FOR ALL NEXT FILE2.fieldA into STACK2
WHERE FILE2.fieldA = val
COMPUTE I/I3=1;
REPEAT STACK1.FOCCOUNT
COMPUTE STACK3(I).fieldA = STACK1(I).fieldA;
COMPUTE STACK3(I).field1 = STACK1(I).field1;
COMPUTE STACK3(I).field2 = STACK1(I).field2;
COMPUTE STACK3(I).field3 = STACK1(I).field3;
COMPUTE STACK3(I).field4 = STACK2(I).field4;
COMPUTE STACK3(I).field5 = STACK2(I).field5;
COMPUTE STACK3(I).field6 = STACK2(I).field6;
COMPUTE I=I+1;
ENDREPEAT
FOR ALL FILE3.INCLUDE fieldA from STACK3;
END

This assume that the formats of the fields in File1, File2 and File3 are the same. It also assumes that the rows from File1 and File2 have the one key (fieldA) and the same number of rows.

Mark
July 28, 2005, 02:12 PM
reFOCUSing
You may also want to take a look at MATCH FILE, MORE and FILEDEF. These functions can all do what you want.