I have a data extension which contains future dates in column 1, then column two has their day of week, column 3 has a specific time of day for each of those dates.

In my email, I need to pull in the next two dates along with their day of week and time based on the send date of the email. The email will run every morning and should pull in the next two future dates/rows. How would I set this ampscript up? I don't even know where to begin.

  • Welcome to SFSE! Can you share with us some of the code you've tried? What have you done so far? It'll be a lot easier to get help if you show us your progress. Thanks! Commented Feb 9, 2017 at 16:37
  • So far, I've tried creating a query with the code below, (pulling the dates within that time frame), from which I could then use the Row function in the actual email to pull the first two rows' information. My only fear is that often times there are more than just 2 dates in the 30 day period, in which i don't want the dates to come into the data extension at random order, so then the Row function wouldn't necessarily pull in the next two dates. Make sense? select * from [ClinicDates] WHERE DATEDIFF(day, GETDATE(), clinicdate) > 0 AND DATEDIFF(day, GETDATE(), clinicdate) < 31
    – Anuj Puri
    Commented Feb 9, 2017 at 17:18
  • Since you are already running a query, can your query only output the correct date for that day's email? Even if you need to output this to a new data extension. Alternatively, have you looked into using the LookUpOrderedRows() AMPScript function? help.marketingcloud.com/en/documentation/ampscript/… Commented Feb 9, 2017 at 20:36
  • LookupOrderedRows() works perfectly. Thanks for the tip!
    – Anuj Puri
    Commented Feb 10, 2017 at 17:00

1 Answer 1


There are a number of AMPScript functions which enable you to retrieve values form a data extension: Lookup(), LookupOrderedRows(), LookupOrderedRowsCS(), LookupRows(), LookupRowsCS().

In Anuj's use case, an order list of dates needs to be retrieved. So, using the LookupOrderedRows() functions would be the appropriate choice.

You must log in to answer this question.

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