Solved

duplicating and incrementing records vfp

Posted on 2010-11-17
5
275 Views
Last Modified: 2012-05-10
Hi:
Trying to wean my staff off excel....
I have 100 customers and 10 products. Each customer has a different price for each product.
Currently I have 100 excel sheets
I have created a customer table with 100 records and a product table with 10 records.
So I believe I need now to create a joining table  (called say "price") comprising 3 columns - customer , product, and price for that product.
Is there any fast and easy way of looping through each customer in the customer table, appending to the price table 10 records for each customer,pulling each product from the product table? So I end up with (100*10) 1000 records? One record for every product for every customer?
 I can make the product code sequential 1-10 if easier!
0
Comment
Question by:ClaytonGlass
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 7

Expert Comment

by:mkobrin
ID: 34153083
i don't know foxpro, but the way i would do it in MSSQL would be as follows:
declare cCustomers scroll cursor for select customerID from customers
declare @i int = 0
open cCustomers
fetch next from cCustomers into @i
while @@fetch_status = 0
BEGIN
	insert into customerProduct(customerID, productID, price) values(@i, product1ID, product1Price)
	insert into customerProduct(customerID, productID, price) values(@i, product2ID, product2Price)
	insert into customerProduct(customerID, productID, price) values(@i, product3ID, product3Price)
	insert into customerProduct(customerID, productID, price) values(@i, product4ID, product4Price)
	insert into customerProduct(customerID, productID, price) values(@i, product5ID, product5Price)
	insert into customerProduct(customerID, productID, price) values(@i, product6ID, product6Price)
	insert into customerProduct(customerID, productID, price) values(@i, product7ID, product7Price)
	insert into customerProduct(customerID, productID, price) values(@i, product8ID, product8Price)
	insert into customerProduct(customerID, productID, price) values(@i, product9ID, product9Price)
	insert into customerProduct(customerID, productID, price) values(@i, product10ID, product10Price)
         fetch next from cCustomers into @i
END
deallocate cCustomers

Open in new window

0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34153085
Customer (id, customer, address, phone, ...)
Product (id, product, defaultprice, ..., order)
CustomerProductPrice (customer, product, price)

SELECT Customer.id As customer, Product.id As product, defaultprice as price;
 FROM Customer, Product;
 ORDER BY Product.order;
 INTO CURSOR temp
SELECT CustomerProductPrice
APPEND FROM DBF('temp')
0
 
LVL 27

Accepted Solution

by:
CaptainCyril earned 250 total points
ID: 34153088
I am sorry
ORDER BY Customer.Customer, Product.order

or


ORDER BY Customer.Customer, Product.Product
0
 

Author Closing Comment

by:ClaytonGlass
ID: 34153220
Thank you very much, Captain!
I would thank mkorbin but since the captain offered a foxpro solution I will go with that. Thanks for the offer,anyway!
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 34153243
You are welcome.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question