Query.
#1

Hello, I came here with a small question when sending query to database.

Can I use such queries, as:

Quote:

UPDATE `field` = 'field3+field4' WHERE `something` = 'value'

Or, I need to get field3, field4 values first, then sum field3, field4 values and then use

Quote:

UPDATE `field` = 'sum of field3, field4' WHERE ...

Thanks in advance.
Reply
#2

Why don't you just test it ...
Reply
#3

becuase it will not work.
Using the syntax UPDATE will only send value's to the database, if you wan't to do this in one query, you should create a DECLARE query, but not sure if this is possible with MySQL or with SA-MP.

It will be something that looks like this:
PHP код:
DECLARE
  
var_num1 NUMBER
  
var_num2 NUMBER
BEGIN 
  var_num1 
:= 0
  
var_num2 := 0
 
  DECLARE 
    
var_mult NUMBER
  
BEGIN 
  SELECT 
`NUMBERINTO var_num1 FROM `usersWHERE `ID`=1;
  
SELECT `NUMBER2INTO var_num2 FROM `usersWHERE `ID`=1;
    
var_mult := var_num1 var_num2
    
UPDATE `usersSET `TOTALNUM`=var_mult WHERE `ID`=1;
  
END
 
END
But this will never work, and it seems that DECLARE is not a valid syntax in MySQL so I can't help you with this.
Reply
#4

I wrote that because it should work, actually.
Reply
#5

ok, now I'm lost? lol.
Reply
#6

I've tried to do this:

mysql_function_query(Handle, "UPDATE `testx` SET `field`=`field2+field3` WHERE `id` = '1'", false, "", "")

with table:

http://clip2net.com/s/2ppTx

Result:
Quote:

[17:29:33] Passing query UPDATE `testx` SET `field`=`field2+field3` WHERE `id` = '1' |
[17:29:33] CMySQLHandler::ProcessQueryThread() - Error will be triggered to OnQueryError()

So I need to get the values?
Reply
#7

pawn Код:
mysql_function_query(Handle, "UPDATE `testx` SET `field` = `field2` + `field3` WHERE `id` = '1'", false, "", "");
Reply
#8

Thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)