0

I'm getting Truncated incorrect INTEGER value: 'D' warning while I try to run the following query:

UPDATE MESSAGES
SET status = CASE
    WHEN 
    (from_id='111111111' AND status='A') THEN 'S'
    WHEN 
    (to_id  ='111111111' AND status='A') THEN 'R'
    WHEN 
    ((from_id  ='111111111' AND status='R') OR
    (to_id  ='111111111' AND status='S')) THEN 'D'
    END
WHERE primary_key = '236499681204'
AND
    (CASE
    WHEN 
    (from_id='111111111' AND status='A') THEN 'S'
    WHEN 
    (to_id  ='111111111' AND status='A') THEN 'R'
    WHEN 
    ((from_id  ='111111111' AND status='R') OR
    (to_id  ='111111111' AND status='S')) THEN 'D'
    END) is not null

I have read the posts MySQL 'Truncated incorrect INTEGER value' and MYSQL Truncated incorrect INTEGER value error. But they dont apply to my case. Here, status is of type VARCHAR(1).

Is there something I'm missing?

Edit

Here's the query for creating the table:

CREATE TABLE  `MESSAGES` (
  `primary_key` bigint(12) unsigned NOT NULL AUTO_INCREMENT,
  `from_id` varchar(9) NOT NULL,
  `to_id` varchar(9) NOT NULL,
  `status` varchar(1) NOT NULL,
  PRIMARY KEY (`primary_key`)
) ENGINE=MyISAM AUTO_INCREMENT=123456789876 DEFAULT CHARSET=latin1

Please help :(

Community
  • 1
  • 1
th3an0maly
  • 3,360
  • 8
  • 33
  • 54

1 Answers1

4

it is not because of status but because of the comparison

(CASE
    WHEN 
    (from_id='111111111' AND status='A') THEN 'S'
    WHEN 
    (to_id  ='111111111' AND status='A') THEN 'R'
    WHEN 
    ((from_id  ='111111111' AND status='R') OR
    (to_id  ='111111111' AND status='S')) THEN 'D'
END) is not null

to avoid the error, cast the result of CASE into a CHAR like this:

CAST( (CASE
    WHEN 
    (from_id='111111111' AND status='A') THEN 'S'
    WHEN 
    (to_id  ='111111111' AND status='A') THEN 'R'
    WHEN 
    ((from_id  ='111111111' AND status='R') OR
    (to_id  ='111111111' AND status='S')) THEN 'D'
END) AS CHAR) is not null

now it should work ok :)