User Guide > Scripting > Script Operators > Comparison Operators
Was this helpful?
Comparison Operators
Comparison operators compare the contents in a field to either the contents in another field or a constant. They may be used alone or in combination with other operators and functions in both record expressions and target field expressions.
Comparison Operator Symbol
Name
==
compares operands
<>
not equal to
<
less than
>
greater than
<=
less than or equal to
>=
greater than or equal to
~
contains
!~
does not contain
like
like
Filter Expression Examples
To select only the records in which the quantity field in the source file is a numeric value of less than or equal to 1000, write this expression:
1000 <= FieldAt("/SOURCE/R1/Quantity")
To select only the records in which the quantity field in the source file is a numeric value greater than 1000, write this expression:
1000 > FieldAt("/SOURCE/R1/Quantity")
To select only the records in which the ordered field in the source file contains values not equal to the values in the shipped field, write this expression:
FieldAt("/SOURCE/R1/Ordered") <> FieldAt("/SOURCE/R1/Shipped")
To select only the records in which the Address field contains "P.O. Box" with or without capitol letters, periods, or spaces, write this expression. This will convert all records for people who have postal box addresses.
FieldAt("/SOURCE/R1/Address") ~ "[Pp]\.[Oo]\. *[Bb][Oo][Xx]"
To select only the records in which the ZIP field does not contain a five-digit number, write this expression. This will only convert records that are missing a zip code.
FieldAt("/SOURCE/R1/ZIP")!~ "[0-9][0-9][0-9][0-9][0-9][-][0-9][0-9][0-9][0-9]"
To select only the records in which the size field in the source file is exactly "10mm", write this expression:
FieldAt("/SOURCE/R1/Size")=="10mm"
To select only the records in which the quantity field in the source file is a text field and must be exactly 1000, write this expression:
Val(FieldAt("/SOURCE/R1/Quantity"))==1000
Comparison Examples
To start an If...Then...Else Statement when a variable has a value greater than or equal to 1000, write this expression:
If variableName >= 1000 Then
  'Execute some code
Else
  'Execute some code
End
To repeat a loop while a variable is less than 5, write this expression:
Dim i
i = 1
While i < 5 'Begin loop.
  'Execute some code
i = i + 1 'Increment counter.
Wend
Less Than (<) Operator
 
Description
Compare two operands to determine if the first operand is less than the second operand
Syntax
result = operand1 < operand2
Remarks
The result of a comparison is True or False. The following rules are used to determine how the operands are compared.
If both operands are numeric, then a numeric comparison is performed.
If either of the operands is a string value, then a string comparison is used.
If either operand is Null, then the result is Null.
Example
The following determines if the contents of the Salary field are less than 75000:
FieldAt("/SOURCE/R1/Salary") < 75000
Greater Than (>) Operator
 
Description
Compare two operands to determine if the first operand is greater than the second operand
Syntax
result = operand1 > operand2
Remarks
The result of a comparison is always True, False, or Null. The following rules are used to determine how the operands are compared.
If both operands are numeric, then a numeric comparison is performed.
If either of the operands is a string value, then a string comparison is used.
If one or both operands are Null, then the result is Null.
Example
The following determines if the contents of the Salary field are greater than 75000:
FieldAt("/SOURCE/R1/Salary") > 75000
Less Than or Equal To (<=) Operator
 
Description
Compare two operands to determine if the first operand is less than or equal to the second operand
Syntax
result = operand1 <= operand2
Remarks
The result of a comparison is always True, False, or Null. The following rules are used to determine how the operands are compared.
If both operands are numeric, then a numeric comparison is performed.
If either of the operands is a string value, then a string comparison is used.
If one or both operands are Null, then the result is Null.
Example
The following determines if the contents of the Salary field are less than or equal to 75000.
FieldAt("/SOURCE/R1/Salary") <= 75000
Greater Than or Equal To (>=) Operator
 
Description
Compare two operands to determine if the first operand is greater than or equal to the second operand
Syntax
result = operand1 >= operand2
Remarks
The result of a comparison is always True, False, or Null. The following rules are used to determine how the operands are compared.
If both operands are numeric, then a numeric comparison is performed.
If either of the operands is a string value, then a string comparison is used.
If one or both operands are Null, then the result is Null.
Example
The following determines if the contents of the Quantity field are greater than or equal to 5.
FieldAt("/SOURCE/R1/Quantity") >= 5
Contains (~) Operator
 
Description
Compares a string with a regular expression pattern to see if the pattern is contained within the string.
Syntax
result = string ~ "pattern"
Remarks
The result of a contains comparison is always True or False. If the pattern is found, a True is returned. If not a False is returned.
The advantage of this operator is that you can search for a particular string or pattern of data in a large field. If that string or pattern exists anywhere in the field, then some action can be taken on the whole field. Also, the option of matching a pattern, not necessarily a literal string, makes the matching capabilities far more flexible.
This operator can process a regular expression as the pattern. It recognizes all special characters. If either operand is Null, the result is Null.
Note:  For information on regular expressions and special characters, see Regular Expressions.
Example
The regular expression ".y.*" means any string containing any character followed by 'y' followed by any number of characters. This expression will test to see if that pattern exists in the string.
If "abcxyzzy" ~ ".y.*" Then
LogMessage("It's in there.")
Else
LogMessage("It's not in there.")
End if
This expression is True for any record where the Field7 contains the letter X somewhere in it.
FieldAt("/SOURCE/R1/Field7") ~ "X"
Does Not Contain (!~) Operator
 
Description
Compares a string with a regular expression pattern to see if the pattern is NOT contained within the string.
Syntax
result = string !~ "pattern"
Remarks
The result of a contains comparison is always True or False. If the pattern is found, a False is returned. If not, True.
The advantage of this operator is that you can search for a particular string or pattern of data in a large field. If that string or pattern does not exist anywhere in the field, then some action can be taken on the whole field. Also, the option of matching a pattern, not necessarily a literal string, makes the matching capabilities far more flexible.
This operator can process a regular expression as the pattern. It recognizes all special characters. If either operand is Null, then the result is Null.
Note:  For information on regular expressions and special characters, see Regular Expressions.
Example
The regular expression ".y.*" means any string containing any character followed by 'y' followed by any number of characters. This expression tests to see if that pattern exists in the string.
If "Big test string" !~ ".y.*" Then
LogMessage("It's not in there.")
Else
LogMessage("It's in there.")
End if
This expression is True for any record where Field7 does not contain the letters "CR" anywhere in it.
FieldAt("/SOURCE/R1/Field7") !~ "CR"
Equals (==) Operator
 
Description
Compare operands and returns a Boolean value based upon whether the comparison is True or not. The operands may be numerical or string values.
Syntax
operand1 == operand2
Remarks
The result of this comparison operator is a Boolean value of True, or False. True returns a value of "-1", while False returns "0".
The following rules are used to determine how the operands are compared:
If both operands are numeric, then a numeric comparison is performed.
If either of the operands is a string value, then a string comparison is used. Enclose strings in quotes ("string").
Example
To compare the contents of the "Account No" field and find each instance of the string "10024", use the following:
FieldAt("/SOURCE/R1/Account No") == "10024"
Caution!  The == operator is a comparison operator. Do not confuse it with the = operator, which is an assignment operator. When you want to assign a value, use the = Operator. If the operator is the second token in a statement and the first token is a variable name, it is interpreted as an assignment. Do not confuse the = operator with this operator. In this instance, if you use the = instead of ==, all "Account No" fields return empty (instead of with Boolean values).
Does Not Equal (<>) Operator
 
Description
Compares two operands to determine if the first operand is not equal to the second operand.
Syntax
result = operand1 <> operand2
Remarks
The result of a comparison is always True, False, or Null. The following rules are used to determine how the operands are compared.
If both operands are numeric, then a numeric comparison is performed.
If either of the operands is a string value, then a string comparison is used.
If one or both operands are Null, then the result is Null.
Example
The following determines if the contents of the Items Ordered field is different than the contents of the Items Shipped field:
FieldAt("/SOURCE/R1/Items Ordered")<>FieldAt("/SOURCE/R1/Items Shipped")
Last modified date: 02/09/2024