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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy fields from one table to another

SitesMasstec

Programmer
Sep 26, 2010
549
Brasil
Hello colleagues!

I have 2 tables: Table A has 30 fields and Table B has 34 fields.

The 30 first fields in table B are the same (names) in table A. So, Table B has 4 additional fields.

How can I select and copy some filtered records from Table A to Table B, without excluding the last 4 fields in Table B?

I used the command bellow, the records were correctly copied to Table B, but the structure in Table B became with the same structure in table A, that is, the last 4 fields in Table B were lost...

Code:
SELECT * FROM TableA.DBF WHERE LOCALIZA=YLOCALIZA ORDER BY CHAVEPAX INTO TABLE TableB.DBF

Thank you,
 
Solution
Yes, I did what EinTerraner advised, and as Doug said, it is the simplest.

Code:
USE TEMPPAX EXCLUSIVE 
DELETE ALL
PACK
USE

USE TEMPPAX 
APPEND FROM PASSAGEIROS FOR LOCALIZA=YLOCALIZA
USE

The file TEMPPAX has now 2 records after a filter is applied (it can have maximum 5 records):
TempPax.jpg

Now, problem is, The Report shows only the first Detail record:

relatreservas7-Run.jpg

This is the report design:
relatreservas7-Design.jpg

What am I missing?

Thank you.
Criss:

In the Detail1 I have the fields from the table RESERVAS.DBF. There must have just one record (LOCALIZA field, example 5005741)

In the Detail2 I have the fields from the table TEMPPAX.DBF. And all the records in the TEMPPAX.DBF must be printed in the Detail2 of the Report, because all records (maximum 5 records) will have the same data in its LOCALIZA field (in the example, 5005741).

The concept is: the table RESERVAS.DBF is a table which contains data about reservation for one cruise (company, ship, cabin, etc)

The TEMPPAX.DBF has records about passengers of that travel reservation (a cruise cabin can accomodate up to 5 passengers)

These travel passengers are filtered from another table (PASSAGEIROS.DBF), which can contain thousands of passengers. But for this Report, I need the data from RESERVAS.DBF which has the LOCALIZA number 5005741, and all the passengers (maximum possible is 5).
 
Well, you just explained why only 1 record is printed. You only have 1 report driving workarea, even when you add a second detail band.
 
Hello, Criss!
I have not understood about "driving workarea" you mentioned above, but the problem was just solved this way:

1) I used the Report Wizard to create a "One-to-Many"
cao2-Design.jpg

2) I ran it to test:

cao2-Run.jpg

3) As it was ok, I copied the fields from my original report (which was not working as expected) to the areas of the report created with the Report Wizard.

4) And ran it:
relatreservas8-Run.jpg

This report, in the Design mode, seems to be the same as a former report that was just showing the first child record (with just one Detail band), the same structure shown in 1) above.

The problem was solved, but I am trying to understand about this "driving workarea" in my original reports (it was my 8th version of this report, during the last four days!)

Thank you very much for your help.
 
Hi,

This report, in the Design mode, seems to be the same as a former report ...

Wrong - you may want to read more carefully the report layout: the data from your former Detail 1 band are now in the Group header 1 called "localiza" whereas the data from your former Detail 2 band are now in the Detail band.

If you own the book "What's New in Nine: Visual Foxpro's Latest Hits", you may want to read the section "Multiple detail bands", p. 106 ff. to see how to implement Multiple detail bands - and if they are required.

Btw you may also want to have a closer look at the demo code I attached to a former thread

hth

MarK
 
Last edited:
I am trying to understand about this "driving workarea"
That's the simplest basic rule of any report. There's always a workare that mainly drives a report, as many records as are in that (FOR condition from the REPORT FORM... FOR command taken into account) is determining the number of records processed in the report run. That's the most basic thing to know about reports.

What you did now effectively causes a SET SKIP TO TEMPPAX in RESERVAS, by making it a one-to-many report. The report is still driven be RESERVAS. The SET SKIP TO works by skipping all records of TEMPAX related to each record in RESERVAS before skipping in RESERVAS and thus ending the report.

You get there much simpler when combining data into one report cursor, as that does not need any such specific setup.
 
You can make the code a lot simpler. And you dnt need the FOR-Clause in the REPORT-Command, because you have already only those records matching "LOCALIZA==YLOCALIZA"

Code:
USE TEMPPAX EXCLUSIVE
ZAP IN TEMPPAX
APPEND FROM PASSAGEIROS FOR LOCALIZA==YLOCALIZA

USE TEMPPAX

REPLACE WTOTMARBR WITH tarimarbr + tpormarbr + tranmarbr + servmarbr ;
        WTOTMARUS WITH tarimarus + tpormarus + tranmarus + servmarus ;
        WTOTAERBR WITH tariaerbr + tembaerbr ;
        WTOTAERUS WITH tariaerus + tembaerus ;
    IN TEMPPAX ;
    FOR .t.

* ------------------------------------------------------------------------------------
SELECT TEMPPAX
GO TOP IN TEMPPAX
SET REPORTBEHAVIOR 90     && Necessário para mostrar termo MARÍTIMO rotacionado a 270 graus
REPORT FORM RELATRESERVAS7 TO PRINTER PROMPT PREVIEW    && era RELATRESERVAS4, sem as linhas acima
SET REPORTBEHAVIOR 80
thisform.release()
RETURN

btw: It is better to use a double "=" for comparisons. A single "=" can also be considered an assignment to a variable and can be confused.
 
Hello dear colleagues!

Mark, Chriss & Ein:

I tried to have more than just one detail in my former versions of the report, but unsucessfully, either (but I think I made a very big mistake, I'll tell you bellow):

relatreservas6-Design.jpg

From my 5th version of the report, clicking by chance in an "empty" area of the report, I saw some points, like there were invisible lines, and I delete them all (big mistake, because when I used the Report Wizard fo generate the CAO2 Report, bellow, it also has these points, as like for invisible line). So I have not erased these points, and the report worked as expected:

cao2-DesignInvisibleLine.jpg

And then I copied all the fields from my original report to the CAO2 report above, as I had told you before, and it worked fine.

Ein:
I have to do REPORT FORM FOR LOCALIZA=YLOCALIZA ... because the Parent table RESERVAS.DBF has lots of LOCALIZA fields, differently from the temporary table TEMPPAX.DBF which has only records with the same LOCALIZA data (it is generated from PASSAGEIROS.DBF table, with thousands of records).

Thank you all for your patience and help.
 

Part and Inventory Search

Sponsor

Back
Top