Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This section described the behavior of SQL Null fields in

The following field definitions are used throughout the text:

Code Block
Define Field(#A) Type(*DEC) Length(9) Decimals(0) Input_Atr(ASQN) Default(*SQLNULL) 
Define Field(#B) Type(*DEC) Length(9) Decimals(0) Input_Atr(ASQN) Default(*SQLNULL)
Define Field(#C) Type(*DEC) Length(9) Decimals(0) Default(*NULL)


Also See

 ASQN (Allow SQL Nulls) attribute

Specifying Conditions and Expressions in the Technical Reference Guide.

Anchor
Assignment
Assignment
Assignment

Info
If you wish to ensure that SQL Null fields are handled via ANSI rules for assignment, enable the *STRICT_NULL_ASSIGN function option. This option causes a fatal error to occur at execution time if the source field is SQL Null and the target field does not have the ASQN attribute.

...


You can also use the .AsValue intrinsic method to treat an SQL Null field as a different value. This is useful for mathematics and concatenation, where SQL Null or *NULL are not appropriate values. In the following example, we now get the result of 5 in #C if #B is SQL Null. However, if #B was 3, #C would be set to 15 because #B.AsValue only affects #B when it is SQL Null.

Code Block
#C := #B.AsValue( 1 ) * 5


Also See

*SQLNULL Keyword
Intrinsic Property .IsSqlNull
Intrinsic Method .AsValue

Anchor
Conditions
Conditions
Conditions

  • To test for SQL Null, you should use *IS *SQLNULL or *ISNOT *SQLNULL, or the Intrinsic Property .IsSqlNull.
  • When using IF_NULL or .IsNull, an SQL Null field will return FALSE.
  • Since SQL Null does not represent a value, when using an equality operator such as *EQ, *LE, *GT to compare fields, and one of the factors of the compare is SQL Null, the comparison will produce an SQL Null. When combined with *OR and *AND operators, an SQL Null factor will continue to produce an SQL Null. A conditional expression that produces an SQL Null will evaluate to false.
  • SQLNULL comparisons will always stay as SQLNULL if the SQLNULL value is true. That is, when an expression is testing an SQLNULL, and there IS an SQLNULL, the expression will keep the SQLNULL value. For these types of scenarios, the *ORIF boolean feature should be used.

...

Condition

Result

#A.IsSqlNull

TRUE

#A.IsNull

FALSE

(#A.IsSqlNull) *orif (#A.IsNull)

TRUE

IF_NULL(#A #B #C)

FALSE

IF_NULL(#C)

TRUE

#A.AsValue(*ZERO) *EQ *ZERO

TRUE

#A *EQ *ZERO

FALSE

#A *EQ #B

FALSE

#A *LE #B

FALSE

#B *EQ #C

FALSE

#B *LE #C

FALSE

Anchor
Expressions
Expressions
Expressions

When expressions are being evaluated, intermediate results retain the SQL Null state. They are ALWAYS strictly interpreted. For example, when #B is SQL Null,  the result of expression '#B + 1' is SQL Null. That is, SQL Null plus 1 is still SQL Null. This is independent of the attributes of any result field.

It is only when the result of the expression is assigned into the result field that a difference in behaviour behavior can occur. If the result of an expression is SQL Null, behaviour depends on whether the result field allows SQL Null and also on the function option *STRICT_NULL_ASSIGN. Refer to Assignment for details.

If you wish to change the value of SQL Null fields to something more appropriate, use Intrinsic Method .AsValue. For example, the result of expression '#B.AsValue(1) + 1' is 2 when #B is SQL Null (and 5 when #B is 4).

...