This may seem like a seemingly simple thing to do, but I haven't had a need to tinker with AMPscript until recently. I'm merely looking up a value in a Data Extension based on a Subscriber ID. Here's what I'd like to achieve:

%%[ VAR @account_id SET @account_id = %%subscriberid%% ]%%
<p>Your score is %%=Lookup("Sample Quiz","A1","account_id",@account_id)=%%</p>

Turns out that my personalization string in a variable is invalid AMPscript, which doesn't surprise me. If I hardcode a variable value it works fine:

%%[ VAR @account_id SET @account_id = 1 ]%%
<p>Your score is %%=Lookup("Sample Quiz","A1","account_id",@account_id)=%%</p>

What's the correct syntax?

2 Answers 2


I always use the AttributeValue() function when dealing with personalization strings. It'll return an empty string if it doesn't exist:

Data Extension

SubscriberID | EmailAddress
238535       | [email protected]


  VAR @account_id
  SET @account_id = AttributeValue("subscriberid")
  set @emailAddress = iif(not empty(@account_id),lookup("AMPScriptTest","EmailAddress","SubscriberID",@account_id),"not found")
<br>account_id: %%=v(@account_id)=%%
<br>Your emailAddress is: %%=v(@emailAddress)=%%

Output (via Email Send Preview)

account_id: 238535 
Your emailAddress is: [email protected]

Within an AMPScript block you do not need additional "%%" around the personalization strings. It will work like the below:

%%[ VAR @account_id SET @account_id = subscriberid ]%%
<p>Your score is %%=Lookup("Sample Quiz","A1","account_id",@account_id)=%%</p>

Similarly you could accomplish the same thing with just the below:

   <p>Your score is %%=Lookup("Sample Quiz","A1","account_id",subscriberid)=%%</p>

You must log in to answer this question.

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