newphpcoder Posted March 13, 2012 Share Posted March 13, 2012 Hi.. I had encountered problem in my update code: UPDATE kanban_checker_doz SET virtual_doz = (count_doz_chemical_weighing + count_doz_compounding + count_doz_extrusion + count_doz_forming); it did not work when I have only data in count_doz_chemical_weighing and the other is NULL. I also tried this code but still the virtual_doz = NULL. UPDATE kanban_checker_doz SET virtual_doz = ((NULLIF(count_doz_chemical_weighing, 0)) + (NULLIF(count_doz_compounding, 0)) + (NULLIF(count_doz_extrusion, 0)) + (NULLIF(count_doz_forming, 0))); Thank you Link to comment https://forums.phpfreaks.com/topic/258811-update-with-operation/ Share on other sites More sharing options...
The Little Guy Posted March 13, 2012 Share Posted March 13, 2012 use ifnull, not nullif Link to comment https://forums.phpfreaks.com/topic/258811-update-with-operation/#findComment-1326828 Share on other sites More sharing options...
newphpcoder Posted March 14, 2012 Author Share Posted March 14, 2012 Using COALESCE solve my problem. update kanban_checker_doz set kanban_doz = coalesce(count_doz_deflashing, 0), virtual_doz = coalesce(count_doz_chemical_weighing, 0) + coalesce(count_doz_compounding,0) + coalesce(count_doz_extrusion,0) + coalesce(count_doz_forming,0), total_doz = coalesce(count_doz_chemical_weighing, 0) + coalesce(count_doz_compounding, 0) + coalesce(count_doz_extrusion, 0) + coalesce(count_doz_forming, 0) + coalesce(count_doz_deflashing, 0) Thank you Link to comment https://forums.phpfreaks.com/topic/258811-update-with-operation/#findComment-1327064 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.