tags:

views:

44

answers:

3

I have this query, which works...

UPDATE `contacts` 
       SET `calls_to`=`calls_to`+1 
  WHERE `contact_no` = '0412345678';

What I also want to do is add a value to the cost field. From my understanding, the way to do this would be...

UPDATE `contacts` 
       SET `calls_to` = `calls_to`+1, 
             `cost_to` = `cost_to`+0.25 
  WHERE `contact_no`='0412345678';

Obviously, as I'm posting here, it's not working as I would expect.

--UPDATE-- As requested, the table structure..

id                  int(255) auto_increment
contact_owner  varchar(255)
contact_no       varchar(11)
contact_name   varchar(255)
calls_to            int(255)
txts_to             int(255)
time_talked_to   int(255)
cost_to            decimal(65,2)
+1  A: 

On first glance the query looks fine. What is the type of the cost_to field? Double check it's not an integral type, since you will then not get the result you are looking for. (As a test, add a larger value, say, 4 to cost_to.)

mdma
A: 

I think your calls_to field as int and cost_to field as in different type, so only you didn't got the result. Check the type of the field.

Karthik
+1  A: 

Check if the datatype for cost_to is int or not.Also update the column if it's value is not null.

UPDATE `contacts` 
       SET `calls_to` = `calls_to`+1, 
             `cost_to` = `cost_to`+0.25 
  WHERE `contact_no`='0412345678' AND
          calls_to is not null AND
          cost_to is not null;
Salil
This seemed to work. Thanks :D(Side note, I had to set the default for calls_to and cost_to to 0.)
adamd