我必须验证表的三列,并根据它们满足的条件更新该表中的error_suggestion列。我正在使用案例。当一种类型的验证失败时,查询工作正常,但当两种类型的验证失败时,它不起作用。执行查询但不根据条件更新error_suggestion。以下是我的询问。
SET @exportof='ExportOf Not Available';
SET @RegDate='Registration Data Not Available';
SET @DOB='Event Date Not Available';
SET @comparedate='Registration Date earlier than Birth Date';
UPDATE Import_Tbl_Error_Log
SET error_suggestion = CASE
WHEN (`ExportOf` is null or `ExportOf`='') THEN @exportof
WHEN (`RegistrationDate` is null or `RegistrationDate`='') THEN @RegDate
WHEN (`bir_le_dob` is null or `bir_le_dob`='') THEN @DOB
WHEN DATE_FORMAT(DATE(`bir_le_dob`),'%Y-%m-%d') >= DATE_FORMAT(DATE(`RegistrationDate`),'%Y-%m-%d') THEN @comparedate
WHEN ((`ExportOf` is null or `ExportOf`='') AND (`RegistrationDate` is null or `RegistrationDate`=''))
THEN Concat(@exportof, ', ', @comparedate)
WHEN ((`ExportOf` is null or `ExportOf`='') AND (`bir_le_dob` is null or `bir_le_dob`=''))
THEN Concat(@exportof, ', ', @DOB)
WHEN ((`RegistrationDate` is null or `RegistrationDate`='') AND (`bir_le_dob` is null or `bir_le_dob`=''))
THEN Concat(@RegDate, ', ', @DOB)
WHEN ((`RegistrationDate` is null or `RegistrationDate`='') AND (`bir_le_dob` is null or `bir_le_dob`='') AND (`ExportOf` is null or `ExportOf`=''))
THEN Concat(@exportof, ', ',@DOB,', ',@RegDate)
ELSE 0
END;
例如,如果ExportOf没有任何值,那么它工作正常,表更新为@ExportOf但是当我检查ExportOf和RegistrationDate(更新查询的第8行)时,这些不会连接,只有@ExportOf更新在表中。其他条件也同样如此。我的MySql版本是5.5.39(如果重要的话)。请帮忙。