To display books borrow history for today and before based on different transaction dates.
%%[ SET @fullname = Concat(FirstName, " ", LastName) SET @rows = LookupOrderedRows("AMPscript - Day 17 Transaction History", 3, "TransactionDate DESC", "SubscriberKey", SubscriberKey) SET @rowcount = RowCount(@rows) ]%% Hi %%=v(@fullname)=%%, %%[ IF @rowcount >0 THEN ]%% This is the confirmation for the books you borrowed today: %%[ SET @row = Row(@rows, 1) SET @book = Field(@row, "BookName") ]%% %%=v(@book)=%% Here are the books you borrowed before. %%[ FOR @i = 2 to @rowcount DO SET @row = Row(@rows, @i) SET @book = Field(@row, "BookName") ]%% %%=v(@book)=%% %%[ NEXT @i ]%% %%[ ELSE RaiseError("This subscriber doesn't have borrow history.", true) ENDIF ]%% Best regards, Next Library
Use LookupOrderedRows() function to returns a specified number of rows in the defined order with specified conditions on fields. The function returns an empty set when no values match.