|Subject:||Re: Action after csv import
|Date:||Tue, 14 Nov 2017 23:27:45 +0100
Le 14/11/2017 à 20:55, Kevin Baker a écrit :
> Hi Everyone,
> I'm trying to determine if this is possible. I need to import a csv
> file, which I know how to do. Once the csv file is imported into a temp
> table (Table A), I need to transfer the records from the Table A into
> another table (Table B), however I need to match up the fields from
> Table A to Table B. For example the first field in Table A is a Date
> field, which would be the 4th field in Table B. I would do the copy
> from Table A to Table B via tcursor.
> I would use enumFieldNames to get the field names from Table A, but
> really not sure how to move forward from this point.
> I was hoping someone might have done this in the past or could point me
> in the right direction.
You could simply use, in a scan loop for instance,
tc.CopyToArray(myArray) to copy the initial data of the record in an
array (or a dynarray) and then, in the same scan loop, with a second
TCursor write in your destination table from the array.
If the fields have the same name in the two tables you would use a
dynarray (the field name will be the index) [to be honest you don't even
need the array in this case simply use tc2.Fieldname = tc1.Fieldname],
if not, an array (the index will be the position of the field, 1,2...)
and then tc2.Fieldname = myArray for example to copy the second field
of tc1 in tc2.Fieldname.
Another possible way is to run an insert query (in SQL or QBE) but with
the TCursor approach you can offer a progress bar for example. You have
more control with TCursor.