Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi!

I can't quite explain my question but here is the explanation:

I have a table:
ID||Products||TotalPrice||Price1||DifPrice1||Price2||DifPrice2||Price3||DifPrice3||
01||Pencil  ||100.00    ||10.00 ||.00      ||25.00 ||.00      ||30.00 ||.00      ||

I want to update the DifPrice with this formula supposing that DifPrice has DifPrice10 and onwards:
TotalPrice - Price1 = DifPrice1
DifPrice1 - Price2 = DifPrice2
DifPrice2 - Price3 = DifPrice3
and etc.

DifPrice and TotalPrice is varchar. So there might be some convertion in the top part of the query.

Thanks for the help!
Posted
Updated 1-Jul-14 18:45pm
v2

1 solution

Oh no, you ought to start learning the correct way of database design[^].
These are some of my observations and suggestions:
First of all, why is data type of price in varchar?
Secondly, why do you need to store price difference as they are derivable from totalprice and the respective prices. Think about date of birth and age, which do you store in the database?
Lastly, you cannot keep adding new columns as many as the number of priceN, instead, change it into 2 tables:
table: product
product_id (primary key)
product_name
table: product_price
product_id
product_price (product_id and product_price are composite key)
both tables are linked through product_id in one to many relationship.
 
Share this answer
 
v3
Comments
mitchiee1226 2-Jul-14 1:36am    
Answers:
1. Prices are in varchar because the program just copied it to the DB from a text-file. Varchar is the easiest way to copy the data though the database because it accepts both letters and numbers.
2. The column I should store in the database is the respective prices.
3. "I want to update the DifPrice with this formula supposing that DifPrice has DifPrice10 and onwards" - What I mean about this is the formula continues until DifPrice10. Supposing I have DifPrice until 10.
This is what I mean:
ID||Products||TotalPrice||Price1||DifPrice1||Price2||DifPrice2||Price3||DifPrice3||...||Price10||DifPprice10||
01||Pencil ||100.00 ||10.00 ||.00 ||25.00 ||.00 ||30.00 ||.00 ||...||2.00 ||.00

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900