2

From reading the AmpScript Lookup docs and seeing numerous examples online it seems that the logic of a simple AmpScript lookup can be stated thusly: From {This Data Extension} Return {The Value In This Column} Where {The Value In This Column} Is {This Value}. So if I for example have a simple DE

id, first, last, favColor
1, steve, hamaker, green
2, megan, hartman, orange
3, jason, smith, blue

And I do a simple lookup like so

Set @FavColor = Lookup("fav_colors_de","favColor","id","id")

Shouldn't I be able to then use the value within @FavColor within an IF statement?

%%[IF NOT EMPTY (@FavColor) THEN]%%
Your Favorite Color is: %%favColor%%
%%[ENDIF]%%

But the issue is that regardless, I always have an empty value.

2

You need to reference the id variable in your lookup function.

Also, you're outputting a personalization string for favColor not the variable that you're setting in your AMPScript block.

Should be something like this:

%%[
var @id, @favColor
set @id = AttributeValue("id")
Set @favColor = Lookup("fav_colors_de","favColor","id", @id)

]%%

%%[IF NOT EMPTY (@FavColor) THEN]%%
Your Favorite Color is: %%=v(@favColor)=%%
%%[ENDIF]%%
1
  • Ah I see! Thanks for the insight - obviously 'id' needs to have a value..otherwise it's not pointing anywhere. Such a simple mistake! – Stephen Boyette Aug 9 '16 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.