我有一个列调用isDifFromother,它保持1或2(默认设置为0)。当我更新一行时,如果isDifFromother值的值为0,我想设置2。如果它的值为1,我想保持原样。
如何在我的更新查询中检查该条件。
这是我的查询...,
UPDATE `customer` SET `name`='" + name + "', `isPackage`='" + packageID + "', `billing_ID`='" + biling_ID + "', `isDifFromother`=IF customer.isDifFromother = '1' THEN '2' END IF WHERE `id`='" + cusID + "';
但它嵌入了错误。
if语句不正确,应为
UPDATE `customer` SET `name`='" + name + "', `isPackage`='" + packageID + "', `billing_ID`='" + biling_ID + "', `isDifFromother`=IF(customer.isDifFromother = '0','2',customer.isDifFromother) WHERE `id`='" + cusID + "';
以下情况
`isDifFromother`=IF(customer.isDifFromother = '0','2',customer.isDifFromother)
如果其0保持原样,则将isDifFromother = 2设置。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句