'截断错误的INTEGER值'错误

时间:2012-10-04 15:55:28

标签: mysql sql

当我尝试运行以下查询时,我收到Truncated incorrect INTEGER value: 'D'警告:

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

我已阅读帖子MySQL 'Truncated incorrect INTEGER value'MYSQL Truncated incorrect INTEGER value error。但他们不适用于我的情况。此处status的类型为VARCHAR(1)

我有什么遗失的吗?

修改

以下是创建表的查询:

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

请帮助:(

1 个答案:

答案 0 :(得分:4)

这不是因为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) is not null

为避免错误,请将CASE的结果投射到这样的CHAR中:

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

现在它应该可以正常工作:)