I have a customer_data_extension that consists of customers with their customer_id.

I'm creating an email with conditional content, so IF customer exists in customer_data_extension then show this content, to find the customer I will be using customer_id. I want to know if it's possible to do this in ampscript and how? I've tried not empty and != "". The condition only works if it can find a match in the data extension, whereas I need the condition to also work when it can't find a match. Here is my working code.

<td align="center">
        /* checking for customer_id */
        VAR @customer_id_look_up
        SET @customer_id_look_up = Lookup("Customer_Data_Extension", "customer_id", "customer_id", customer_id)

    %%[IF @customer_id_look_up != " "  THEN]%%

    <p class="headline">content 1 because customer_id exists in data extension=%%</p>


    <p class="headline">content 2 because the customer_id doesn't exist in the data extension</p>


1 Answer 1


I’d go for LookupRows and RowCount.

If rowcount > 0 then display one type of content, else display another type of content.

Below modified example form the ampscript.guide does just that:

var @rows, @row, @rowCount, @region, @i

set @region = AttributeValue("Region") /* value from attribute or DE column in send context */
set @region = "North" /* or a literal value */
set @rows = LookupRows("LoyaltyMembers","region", @region)
set @rowCount = rowcount(@rows)

if @rowCount > 0 then  ]%%

Some content if record exists

%%[ else ]%%

No rows found so different content here

%%[ endif ]%%
  • Thank you, that has worked perfectly.
    – T01
    May 5 at 15:41

You must log in to answer this question.

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