2012-10-04 79 views
0

我越來越Truncated incorrect INTEGER value: 'D'警告,而我試圖運行下面的查詢:「截斷不正確INTEGER值」錯誤

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。但他們不適用於我的情況。這裏,statusVARCHAR(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 

請幫助:(

+0

您好再次:)。你是如何定義'primary_key'字段的? – Parado

+4

請顯示您的表格定義 –

+1

'MySQL!= SQL' – NullUserException

回答

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 

現在它應該工作正常:)

相關問題