0

我在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 wrong INTEGER value'MYSQL Truncated wrong 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

请帮忙 :(

4

1 回答 1

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

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

于 2012-10-05T07:04:49.057 回答