Trying to figure out a way to return a value from a Field in a data extension only if the field is non-blank.

I want to send an email with a personalized greeting ("Hey, First Name! Here's this week's content") but the issue I'm running in to is that not everyone has provided their first name.

I'm wondering if there's a way to run a check that says

If first name is blank then return "Here's this week's content" else Return "Hey, First Name, Here's this week's content".

2 Answers 2


This is a common case for AMPscript, and there are various ways to accomplish this. I prefer this method, whereby all the copy and logic lives in the AMPscript block, with just the result being shown in the HTML.

    SET @firstname = AttributeValue("FirstName")
    SET @SalutationA = Concat("Hey, ",@firstname," Here's this week's content")! 
    SET @SalutationB = "Here's this week's content"

    IF @firstname == "" THEN
      SET @text = @SalutationB 
      SET @text = @SalutationA


  • This solutions seems quite elegant. However, when I tried to implement I got the error: The script condition contains an invalid comparison operator. Condition: @firstname = "" Is there another way I should be looking at a cell containing a null value?
    – Eczekner
    Dec 15, 2017 at 12:57
  • it needs to be two equal signs. "==" Dec 15, 2017 at 14:30
  • Also can use IF EMPTY([at]firstname) and I would change the first variable to be SET [at]firstname = AttributeValue("FirstName") as this will better handle NULL values and more.(Plus it will make @AdamSpriggs happy and we all want that!) [at] used in place of 'commercial at' sign as comment will only let me use one. Dec 15, 2017 at 14:37
  • This all makes sense to me, but for some reason SalutationA is returning "Hey, @firstname! Here's this week's content" rather than filling in firstname with the actual name.
    – Eczekner
    Dec 15, 2017 at 18:22

You can use ampscript if statement something like:

%%[ If Not Empty @firstname Then ]%% 
show first name here
%%[ Else ]%%
show backup if empty
%%[ Endif ]%%

You must log in to answer this question.

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