Personalization Strings cover the simple cases. AMPscript is what you reach for when the email needs to do more than inject a single value.
Three patterns we use on almost every production engagement:
- Looking up values from a non-sendable Data Extension
- Tiered conditional content based on subscriber state
- Formatting dates and numbers for display
The AMPscript block is wrapped in %%[ ... ]%%. Output of a variable comes from %%=v(@varName)=%%.
Pattern 1: Lookup across Data Extensions
The sendable DE usually doesn't hold every attribute the email needs. A common case: the email sends from each subscriber's assigned Sales Rep, but the rep's name, email, and phone live in a separate SalesRep_DE, not duplicated into the sendable.
Fetch the rep data at send time with Lookup():
Lookup syntax:
The pair that gets swapped constantly is positions 2 and 3 - FieldToReturn and FieldToMatch. Order wrong = Lookup silently returns empty. No error, just blank output.
Pattern 2: Tiered conditional content
Loyalty emails routinely say different things depending on the subscriber's current state:
Two scripting blocks here: the top one sets variables, the inline IF decides whether to render a paragraph at all.
When conditional content is structural (show or hide whole blocks of HTML), either AMPscript inline IF or a Dynamic Content Block works. Dynamic Content is nicer for non-developers to maintain; AMPscript is nicer when logic is complex or needs lookups.
Pattern 3: Formatting values for display
Raw data rarely matches how humans read it. 1500000 in a DE should display as 1,500,000 VND in the email. 2024-01-15 should display as 15/01/2024.
Format(value, "N0") = number with thousands separators, no decimals. Format(date, "dd/MM/yyyy") = day/month/year. Now() = current send time.
Other useful format strings:
- "yyyy-MM-dd" for ISO dates
- "hh:mm" for 12-hour time
- "HH:mm" for 24-hour time
- "C" for currency (locale-aware, use cautiously in international sends)
The three mistakes we still see
Mistake 1: No EMPTY() check after Lookup
Lookup returns empty when the match fails. Without an explicit fallback, the email just shows nothing where the data should be. Always:
Mistake 2: Unclosed AMPscript blocks
Forgetting to close %%[ breaks rendering on the whole email. Test in Preview & Test immediately after writing AMPscript - if the Preview shows error text, the syntax is wrong and the email won't send.
Mistake 3: AMPscript in the Subject Line
Same rule as Personalization Strings: Subject Line does not render AMPscript. Move the logic upstream, pre-compute a field in the DE, and use a plain Personalization String in the subject.
Takeaway
AMPscript earns its place in the project when the email needs cross-DE data, conditional logic, or formatted values. Three patterns cover 90% of the real-world use cases: Lookup with IF EMPTY fallback, IF/ELSEIF/ELSE for tiers, and Format() for numbers and dates. Preview & Test with multiple data profiles catches both logic bugs and syntax errors before they go to the full list.
Writing AMPscript for a production SFMC build? Our Salesforce team reviews and ships complex AMPscript on Marketing Cloud engagements. Get in touch ->
See our full platform services for the stack we cover.