Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Insert blank records
Message
 
À
27/01/2005 11:33:16
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 6
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
00981237
Message ID:
00981598
Vues:
34
>I have a database (regular table) that has records in it sorted by a field called "customerid". The "customerid" field identifies the customer ID number of individual records. There are multiple records with the same customer ID number. I want insert two empty/blank records after each group of records with the same customer ID number.
>
>What is the code to do that?

Well, this would be a non-ortodox way to do it, but the request is also not very ortodox <bg>
SELECT DISTINCT CustomerID FROM Customers INTO CURSOR c_customersIDs readwrite
APPEND FROM DBF('c_customersIDs')

* Now in c_customersIDs we have all the IDs duplicated in a field called TempID

SELECT * from customers INTO CURSOR c_customers readwrite

* Now we have the customers in a cursor.
* We add from our CustomersIDs cursor to have all the extra records required

APPEND FROM DBF('c_CustomerIDs')

* Now we have the table, but the added records are not in order so we need an extra step
* Because the added records only have value in the first field
* I will order the cursor by the second field descending, putting the added records at the end
* of each customer id's change

SELECT * from c_Customers ORDER BY 1, 2 descending INTO CURSOR c_customers readwrite
BLANK FOR EMPTY(SomeOtherField)
BROWSE last
I did my test with one of my tables, and In my tests I used a second CustomerID as TempID and while writing this i deemed it unnecessary, so it might not work now that I removed it, but now I do not have more time for testing this, but I think it should work
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform