Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
From a record of a table to another
Message
De
13/10/2007 11:21:14
Mike Yearwood
Toronto, Ontario, Canada
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01260800
Message ID:
01260824
Vues:
10
This message has been marked as a message which has helped to the initial question of the thread.
>I have two tables with the same structure, and I using the got below
>
>Scan table1
>
> select table 2
> appe blank
> ** if this record is not in table1 yet
> ** get data of this record to current record of table1
>endscan
>
>Is it possible to append data from a record of table1
>to a redord of table2 without having to store table1 fields to variables?

Hi Moises

Look at this code. See that the insert command is made as a string by a separate function - so it could be used on any table.
USE TABLE1 IN (SELECT("TABLE1"))
USE TABLE2 IN (SELECT("TABLE2"))

LOCAL m.lcCmd
m.lcCmd = GetInsertCommand("TABLE1")

SELECT MEMBERS
SCAN
  INSERT INTO TABLE2 &lcCmd.
ENDSCAN
RETURN

*Save this as GetInsertCommand.PRG or PROCEDURE GetInsertCommand
LPARAMETERS m.tcSourceTable
LOCAL m.lnI, m.lcFieldName, m.lcSourceFields, m.lcTargetFields
STORE "" TO m.lcFieldName, m.lcTargetFields, m.lcSourceFields
FOR m.lnI = 1 TO AFIELDS(laFields,m.tcSourceTable)
  m.lcFieldName = ALLTRIM(laFields[m.lnI,1])
  m.lcTargetFields = m.lcTargetFields + m.lcFieldName + ","
  m.lcSourceFields = m.lcSourceFields + m.tcSourceTable + "." + m.lcFieldName + ","
ENDFOR m.lnI
m.lcTargetFields = LEFT(m.lcTargetFields,LEN(m.lcTargetFields)-1)
m.lcSourceFields = LEFT(m.lcSourceFields,LEN(m.lcSourceFields)-1)
RETURN "(" + m.lcTargetFields + ")" ;
+ " VALUES (" + m.lcSourceFields + ")"
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform