So I'm creating an email that needs to populate a coupon code from their email address.

The DE is called CouponCode

Field values are Email Address and Coupon.

The only information I have in the DE is Email Address and Coupon.

I thought I could get away with just declaring the coupon (%%coupon%%) and it'll find it automatically, but it didn't (I also tried %%=lookup(CouponCode,Coupon)=%% and that didn't work).

I'm not super familiar with AMPScript but I've used SQL queries before to pull info in the last platform I used. Is there a logic needed to populate the data? Do I need to link the DE to another DE/database to work? I'll be constantly adding new codes for different promotions, so that would be an extra step that I'd like to avoid. Also, some of these will be part of automated campaigns that will get replenished over time (though for right now it's for a one-off).

2 Answers 2


You've got to establish the lookup parameters in order to retrieve the coupon codes. The emailaddr is a personalization string present in all email sends.


var @couponCode, @emailAddr
set @emailAddr = AttributeValue("emailaddr")
set @couponCode = Lookup("Coupons", "CouponCode", "EmailAddress", @emailAddr)

CouponCode: %%=v(@couponCode)=%%


  • Thanks! Does it matter where in the HTML the query is placed? In the code to display the variable, I only put in '%%=v(@couponCode)=%%' not 'CouponCode: %%=v(@couponCode)=%%' (guessing that's just explaining what that is...)? Example: <p>Use Coupon Code:<b>%%=v(@couponCode)=%%</b></p>
    – Joeshmo
    Commented Dec 6, 2016 at 15:58
  • The %%=v(@couponCode)=%% can be anywhere in your HTML as long as it's after the %%[ ]%% AMPScript block Commented Dec 6, 2016 at 16:47
  • Thanks, though I did see an error in that the order in the Lookup was wrong (its sequential order: DE --> Row/Column). CouponCode should be before Coupons. Otherwise this was perfect. Thanks!
    – Joeshmo
    Commented Dec 8, 2016 at 15:30
  • Sure about that? The first parameter (according to the documentation) is Name of data extension from which to return specified value. The second is Name of column from which to return value. Commented Dec 8, 2016 at 15:34
  • Yeah, that's what I meant. Think the example had it flipped by accident ('CouponCode' was the DE the way I had it)
    – Joeshmo
    Commented Dec 8, 2016 at 21:15

just look for the presence of the coupon column in some list attribute with same name because if it does, then the precedence will take list attribute first and that being blank will display nothing.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .