Using the Lookup Function In AMPScript

I would like to start by saying that AMPScript is a very powerful tool to use when creating dynamic emails within ExactTarget. It is well documented and has a diverse range of functionality to do the very simplest tasks to the most complex. One of the most common uses is to access data within Data Extensions for creating dynamic content within emails. ExactTarget provides several different methods to lookup this data, but fails to detail one important aspect and that is multi-conditional lookups. Let’s take a look at what ExactTarget provides us for a basic lookup call using the syntax Lookup(Data Extension, Order By Column, Condition Column, Condition Value):

%%=Lookup("PostalCode", "City", "PostalCode", 46016)=%%

This is a single condition lookup that targets the “PostalCode” data extension, sorts by “City”, and finds only cities with “PostalCode” equaling 46016. But what if I wanted to find cities with “PostalCode” equaling 46016 and 45236? Without a multi-conditional lookup I would have to look over the result set of the first lookup and perform lookups for each of those results. That route is very time consuming and will slow down the send time of the email greatly. What ExactTarget fails to mention about their Lookup function is that they are all multi-conditional. The real syntax should be: Lookup(DE,Order,Condition1,Value1…Conditionn, Valuen). This would then make our lookup for multiple postal codes as such:

%%=Lookup("PostalCode", "City", "PostalCode", 46016, "PostalCode", 45236)=%%

This will create the multi-conditional lookup that we were wanting and like the proposed syntax one can create infinitely many conditions. Hope this helps in creating your dynamic emails!

  1 comment for “Using the Lookup Function In AMPScript

  1. Saf
    April 20, 2017 at 10:56 am

    how can I apply OR condition ? for example if I want to create the condition like “PostalCode”, 46016 OR “PostalCode”, 45236 ?

Leave a Reply

Your email address will not be published.