AMPScript Lookup Examples

In Marketing Cloud, there are several ways to retrieve external data with AMPScript inside your email, landing page or SMS message. Here are few ways to go about it.

Suppose you have a Data Extension that contains these rows (and is not your sending audience):

LookupColumnDEColumn1DEColumn2
wheeNeoKeanu Reeves
wheeTrinityCarrie-Anne Moss
wheeMorpheusLaurence Fishburne
whoaAgent SmithHugo Weaving

Lookup value of single column value from a certain row

Output

DEColumn1 is Agent Smith

Lookup multiple column values from a single row

Output

DEColumn1 is Neo, DEColumn2 is Keanu Reeves

Lookup multiple column values from multiple ordered rows

Output

Row 1, DEColumn1 is Trinity, DEColumn2 is Carrie-Anne Moss
Row 2, DEColumn1 is Neo, DEColumn2 is Keanu Reeves
Row 3, DEColumn1 is Morpheus, DEColumn2 is Laurence Fishburne

For further reference:

Updates

  • 2017-10-19 – Added example Data Extension and output



Leave a Reply

15 Comments on "AMPScript Lookup Examples"

Notify of
avatar
Sort by:   newest | oldest | most voted
Javier
Guest

Hello, I cant access the data extension data with a lookup function if it is a shared data extenion

Sebastien
Guest

Hey Adam,
I’ve been trying to retrieve a row filtering on a datetime field.
I’ve tried so many different datetime formats and am still not getting any results.
To be precise what I am trying to do is update a row in SSJS but it is the same issue in AMPScript.
Have you ever managed to retrieve/update a row using a datetime value?
Thanks for your help!
Sebastien

trackback

[…] AMPScript Lookup Examples […]

chethan
Guest

is there a way to find lookup unique records?

Ryan
Guest

Hey Adam,

I love that you have the code laid out, but it is hard to see how that would connect to the data extension, without having the data extension info listed. Could you possibly give an example with this code using example data extension info. I am working in Marketing cloud. I don’t know if that makes a difference for you.

Thanks for any help!

Ryan
Guest

Thanks for adding the example output!

Any chance you can add an example where the @numRowsToReturn isn’t 0? I’m attempting to complete this with a set number (3), but its only returning a single row.

wpDiscuz