SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 calculate new price based on percentage
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

goliath_75
Starting Member

1 Posts

Posted - 09/11/2013 :  05:39:26  Show Profile  Reply with Quote
I've got two database tables: product and original_prices. Both tables have a field product_id (key) and price. I want to add a certain percentage to all prices from table original prices, let's say 50%), and store (update) these prices within table product.

I've got this, but it fails at the percentage calculation.

UPDATE product, original_prices SET product.price *= (1 + original_prices.original_price * 50 /100) WHERE product.product_id=original_prices.product_id


It gives me the error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*= (1 + original_prices.original_price * 50 /100) WHERE product.product_id' at line 1

I hope someone can help me out with this.

khtan
In (Som, Ni, Yak)

Singapore
17430 Posts

Posted - 09/11/2013 :  06:07:52  Show Profile  Reply with Quote
try posting at dbforums.com or a mysql site. SQLTeam is on Microsoft SQL Server


KH
Time is always against us

Go to Top of Page

Lumbago
Norsk Yak Master

Norway
3271 Posts

Posted - 09/11/2013 :  08:33:57  Show Profile  Reply with Quote
Syntax is way off:

UPDATE a SET a.price = (b.original_price * 1.5) 
FROM product a 
  INNER JOIN original_prices b
WHERE a.product_id=b.product_id


- Lumbago
My blog-> http://thefirstsql.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000