PDA

View Full Version : Simple sustract operation in a querry


wert
04-25-2003, 07:45 PM
Hi there, Im trying to query something like this:
UPDATE Caja SET Monto -$SubTotal WHERE Tienda = $Tienda
let's say that :
$SubTotal = 50
$Tienda = 1 (it really does not matter, it's just an index)

and obviouslly it does not work !!
I want to save me the "Talacha" of select first the Monto from Caja, make the simple arithmetic operation in php an then put the new value back on the table (Caja).

if any one out there can helpme to avoid the "TAlacha" it will be great, Thnx.

raf
04-25-2003, 07:52 PM
Huh? What's all that about man. Anyway, i suppose you want something like
sqlquery="UPDATE Caja SET Monto = Monto-" . $SubTotal. " WHERE Tienda =". $Tienda

wert
04-25-2003, 08:01 PM
nop not really, lets say that my query is like this:
UPDATE Caja SET Monto -50 WHERE Tienda = 1;
that query gives me a syntax error, I want to know the right way to make a substraction in the very same query.
I dont know some thing like this : SELECT * FROM the_table where value = (5+2);
and that this query returns all te registryes from The_table where value is 3

raf
04-25-2003, 08:22 PM
Like this:
UPDATE Caja SET Monto=Monto-50 WHERE Tienda = 1;
the value for Monto will be -50 for the record with value Tienda = 1
(same as my previous post, buth there it needs to be a PHP string (or some other language) cause there are two variables in. The string gets build when it is parsed by the webserver, and is then sent to the DB --> the RDBM actually)

SELECT * FROM the_table where value = (5+2);
and that this query returns all te registryes from The_table where value is 3

3? and not 7?

wert
04-25-2003, 09:44 PM
Sorry I didn't get it from your first post, my fault, but that was just the sytax I was looking for Thnx ;)

raf
04-25-2003, 09:57 PM
No problem. Glad you found it.