# Calculation with NULL values

**URL:** <https://forum.servoy.com/t/calculation-with-null-values/973>\
**Category:** Classic Servoy\
**Created:** [January 8, 2004, 10:25pm UTC](https://forum.servoy.com/t/calculation-with-null-values/973 "2004-01-08T22:25:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rainer\_dsp](https://avatars.discourse-cdn.com/v4/letter/r/e0b2c6/32.png) [@rainer\_dsp](https://forum.servoy.com/u/rainer_dsp)\
**Post date:** [January 8, 2004, 10:25pm UTC](https://forum.servoy.com/t/calculation-with-null-values/973/1 "2004-01-08T22:25:33Z")

</div>

I need this simple calculation:

(field B/C/D are looked up by relations from a MYSQL DB)

field\_A = field\_B + field\_C + field\_D

IF field\_B/C/D is \>= 0, the calculation is ok, but if a single field does not contain a value → NULL, the calculation of field\_A is not possible.  
Is there a way to define a NULL value as “0” ?  
Or do i need to use if/then statements for each field before i can calculate the result ?  
Is there a workaround ?

Thank you

Rainer Boehm

---

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.servoy.com/u/Ron)\
**Post date:** [January 10, 2004, 11:49pm UTC](https://forum.servoy.com/t/calculation-with-null-values/973/2 "2004-01-10T23:49:40Z")

</div>

I did the same calculation and mine works fine.  
The work around you propose is not nes because you can select the  
‘allow null’ box in your dataprovider window. ![:wink:]( "Wink")

Ron

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [January 11, 2004, 10:36am UTC](https://forum.servoy.com/t/calculation-with-null-values/973/3 "2004-01-11T10:36:21Z")

</div>

The underlying SQL might have problems calculating with the null value.

What you could do as a workaround is first evaluate the fields you want to calculate with. If ino of them has a null value, exclude it from the calculation (if-then-else sortlike statement)

Paul

---

<div class="post-metadata">

**Author:** ![Jan\_Blok](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@Jan\_Blok](https://forum.servoy.com/u/Jan_Blok)\
**Post date:** [January 13, 2004, 11:32pm UTC](https://forum.servoy.com/t/calculation-with-null-values/973/4 "2004-01-13T23:32:39Z")

</div>

> rainer / dsp:  
> field\_A = field\_B + field\_C + field\_D

one solution for field\_A is:

```auto
if (field_B == null) field_B = 0;
if (field_C == null) field_C = 0;
if (field_D == null) field_D = 0;
return field_B + field_C + field_D;

```
