Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SCATTER NAME Problem
Message
De
20/12/2002 07:49:30
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00734564
Message ID:
00734826
Vues:
21
>I want to SCATTER a record from one table, add some
>fields to the record object, then GATHER into another table.
>
>Both tables have the same structure, with the exception of 4 extra
>fields on table 2.
>
>To accomplish this, I SELECT out the record, plus the extra fields, then
>SCATTER to the record object. Is there a different way to do this?
>
>
>SELECT Table1
>nRec = RECNO()
>
>SELECT *, DATETIME() AS Field1, SPACE(11) AS Field1,;
>       SPACE(1) AS Field3, SPACE(2) AS Field4;
>  FROM Table1;
>  WHERE RECNO() = nRec;
>  INTO CURSOR Temp1
>
>SCATTER NAME oRecord MEMO
>
>oRecord.Field1 = DATETIME()
>oRecord.Field2 = "Some Value"
>oRecord.Field3 = "A"
>oRecord.Field4 = "01"
>
>SELECT Table2 APPEND BLANK
>GATHER NAME oRecord MEMO
>
Kevin,
IMHO what you do is one of the best methods and nothing wrong with it. As always in VFP there are many ways of doing the same thing. I might do it like this :

*Assuming tables do not have a PK but f1,f3,f4 together constitute a unique record
local oRecord
select table2
append from table1 for f1 = table1.f1 and f3=table1.f3 and f4=table1.f4
scatter name oRecord memo
oRecord.Field1 = DATETIME()
oRecord.Field2 = "Some Value"
oRecord.Field3 = "A"
oRecord.Field4 = "01"
gather name oRecord memo fields Field1,Field2,Field3,Field4
Or with structures matching as you said except 4 on the 'right' (assuming tables have no general fields and last for fields are in that order) :
LOCAL ARRAY arrRecord[1,FCOUNT('table2')]
local lnOffset
lnOffset = fcount('table1')
SELECT table1
SCATTER TO arrRecord MEMO
arrRecord[1,lnOffset+1] = datetime()
arrRecord[1,lnOffset+2] = "Some Value"
arrRecord[1,lnOffset+3] = "A"
arrRecord[1,lnOffset+4] = "01"
INSERT INTO table2 FROM ARRAY arrRecord
Making the array 2 dimensional is not mandatory in this particular case but it more resembles multirow table structure (I sometimes use this to transfer multiple records at once).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform