Jump to content

Update with + Operation


newphpcoder

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.