View Single Post
Old 02-26-2008, 05:25 PM   #2 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Something like the following? The @fValue variable is the amount to deduct.

sql Code:
UPDATE
    cash,
    (
        SELECT
            @fValue:=1.99,
            @fCash:=(cash - @fValue),
            @fCash:=IF(@fCash > 0, cash - @fValue, 0)
        FROM
            cash
        WHERE
            id = 1
    )
    AS fCash
SET
    cash = @fCash
WHERE
    id = 1
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
Nor (02-26-2008)