Expression and Null value

Posts   
 
    
Barry
User
Posts: 232
Joined: 17-Aug-2005
# Posted on: 23-Feb-2006 04:39:48   

I'm writing a expression to do calculation the values of two fields as the following code. Field2 may contain null value in database, therefore result of subtraction is null for those with null value if Field2. How to handle null value in expression? Thank you very much!


fields.DefineField(OrderFields.Field1, 0);
fields[0].AggregateFunctionToApply = AggregateFunction.Sum;
fields[0].ExpressionToApply = new Expression(OrderFields.Field1, ExOp.Sub, OrderMaterialFields.Field2)

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-Feb-2006 07:28:28   

How to handle null value in expression?

What do you mean?

normaly in the database having a value - null = null and if you do aggregation (Sum), the end result will be null.

If you don't want this behaviour, I think you may have the following options:

1- use a default value in the database and don't use null in the field you want to have arithmatic operations upon.

2- execlude the null rows by using a Filter.

3- Use a CASE statement to replace (value - null = null) by a value maybe 0, in order not to ruin your Sum operation. You can do this by implementing IExpression as shown in the following thread http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3829 Or you might implement all your query in a database view and map it to an Entity or a TypedView.