Scripting > UNICOM Intelligence Function Library > Miscellaneous functions > Decode
 
Decode
Provides the same functionality as an IF-THEN-ELSE statement (used for OnNextCase events).
Syntax
Decode(Expression, search, result, [search,result]...[,default])
Parameter
Expression
Type: None
The value to compare.
Search
Type: None
The value that is compared against Expression.
Result
Type: None
The returned value if Expression is equal to Search.
defaultValue
Type: None
Optional. If no matches are found, it returns the default. If the default is omitted, then the decode statement returns null.
Note There are variable pairs for Search and Result.
Remarks
The function searches Expression and returns the related Result if Search is found. Otherwise, the function returns defaultvalue. If defaultvalue is not set, the function returns null.
There are restrictions when using this function:
Expression can include the following types: Long, Double, Text, Date, Categorical, Boolean.
Expression and Search should be the same data type; the function will issue an error if they are different.
Example
Decode(Expression, "USA", "America",
"UK", "UnitedKindom",
"OtherCountries")
The following table shows the Expression and retrieved result values:
Expression
Result by Decode()
“USA”
“America”
“UK”
“UnitedKindom”
“German”
“OtherCountries”
Decode(Expression, 1, "Red",
2, "Yellow")
The following table shows the Expression and retrieved result values:
Expression
Result by Decode()
1
“Red”
2
“Yellow”
3
null
See also
Miscellaneous functions