[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql
Subject:    User variables in update statement
From:       Scott Haneda <lists () newgeo ! com>
Date:       2007-07-10 18:59:40
Message-ID: C2B9252C.58398%lists () newgeo ! com
[Download RAW message or body]

Is it possible to use user variables in an update statement, I can find only
scant docs on it, but they do not pertain to what I am trying to do.

Given this select:

SELECT user_id, order_status, quantity_chosen, month_price, each_price,
sales_tax, sales_tax_rate,
@NEW_each_price:=(each_price + .06) as NEW_each_price,
@NEW_month_price:=(quantity_chosen * @NEW_each_price) as NEW_month_price,
@postage_rate:=(0.30) as postage_rate,
@cost_of_postage:=(quantity_chosen * @postage_rate) as postage,
@taxable_price:=(@NEW_month_price - @cost_of_postage) as taxable,
(@taxable_price * sales_tax_rate) as NEW_sales_tax

As you can see, I am using variables to make some calcs, sure, I can do it
long hand, but it gets long and confusing.

Given the above, I end up with some vars like NEW_month_price,
NEW_each_price etc, I would like to update ... SET price = NEW_each_price,
but of course, that does not work.

Suggestions?
-- 
-------------------------------------------------------------
Scott Haneda                                Tel: 415.898.2602
<http://www.newgeo.com>                     Novato, CA U.S.A.



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql?unsub=mysql-marcsub@progressive-comp.com

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic