MySQL Forums
Forum List  »  Newbie

Updating decimal field w/variable
Posted by: Judy Miller
Date: January 29, 2015 11:17AM

I'm trying to locate a row of data (last row entered) and insert a new row that sets the new the 'cumulativeamt' value to the 'cumulativeamt' from that last row less 10000. This should work...but I keep getting a syntax error. See below:

SET @Total = SELECT `cumulativeamt` FROM `table` WHERE `year`= '2012' AND `name` = 'Apple' ORDER by `id` DESC Limit 1;
SET @Total = @Total – 10000.00;
INSERT INTO `table` (`id`, `year`, `name`, `date`, `datetime`, `todayamt`, `cumulativeamt`) VALUES
(NULL, '2012', 'Apple', CURDATE(),NOW(), -10000.00, @Total);

#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL version for the right syntax to use near ‘SELECT `cumulativeamt` FROM `table` WHERE `year`= '2012' AND `name` = ' ' at line 1

Options: ReplyQuote


Subject
Written By
Posted
Updating decimal field w/variable
January 29, 2015 11:17AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.