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.

OperatorDescription
==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.

1If @age >= 30 then
2  ...
3EndIf

Join Operators 

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

OperatorDescription
andBoth conditions must be true
orEither 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”.
1If (@age >= 30 and @predisposition == "High") or (@age >= 55 and @predisposition == "Normal") then
2  ...
3EndIf

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”.

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

See Also