Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

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

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.

In (Som, Ni, Yak)

17689 Posts

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

Time is always against us

Go to Top of Page

Norsk Yak Master

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->
Go to Top of Page
  Previous Topic Topic Next 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.08 seconds. Powered By: Snitz Forums 2000