Evaluating Conditions in AMPscript

AMPscript supports conditional logic, enabling your marketing team to personalize each message and customer touchpoint.

Comparison Operators

In AMPscript, you can use comparison operators to compare two values. AMPscript uses the operators in this table.

Operator Description
== Is equal to
!= Is not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

These operators are commonly used in If statements. For example, this statement checks to see if the numeric value of the @age variable is 30 or higher.

If @age >= 30 then
  ...
EndIf

Join Operators

You can also use join operators to join multiple conditions. AMPscript includes the join operators in this table.

Operator Description
and Both conditions must be true
or Either condition must be true

You can use parentheses to control the order in which AMPscript evaluates complex expressions.

For example, this If is matched in one of two ways:

  • If the value of the @age variable is 30 or higher and the value of the @predisposition variable is "High"; or
  • If the value of the @age variable is 55 or higher and the value of the @predisposition variable is "Normal".
If (@age >= 30 and @predisposition == "High") or (@age >= 55 and @predisposition == "Normal") then
  ...
EndIf

Not Operator

The not operator reverses the logic of an evaluation. For example, this statement is matched when the value of the @age variable is 55 or higher, and the value of the @predisposition variable is anything other than "High".

If @age >= 55 and not @predisposition == "High"
  ...
EndIf

See Also