I am trying to create a IF statement on a Marketing Cloud email that will display the First Name of the Subscriber if we have one stored in the All Subscriber studio, if they have not been added I was hoping to use "Dear Patient," instead. I am not to familiar with code so I apologize if this is completely off.

Attribute Value for First Name = %%First Name%%

Dear Patient would just be a text value

(IF [%%First Name%%] is Null, %%First Name%%, Dear Patient",")

Almost there. You have some syntax issues and need a bit more to it.

        Set @salutation = "Dear Patient"

        Set @fname = AttributeValue("FirstName")

      IF NOT EMPTY(@fname) AND @fname != "" THEN

          SET @salutation = CONCAT("Dear ", @fname)



Then in your HTML you would output via %%=v(@salutation)=%%.

Another option is the IIF() function.

Dear %%IIF(EMPTY(AttributeValue("FirstName")), "Patient", AttributeValue("FirstName"))=%%

  • Thanks for the help Gortonington I used a combination of yours and Jakes below to come up with this: Dear %%[set @fname = trim(attributevalue('first name'))]%% %%=iif(empty(@fname),"Patient",ProperCase(@fname))=%%, And it works like a charm. Thanks for your time! – Cameron Feb 13 at 17:24

If your sending data extension has a field named "First Name", the attributevalue() function will attempt to pull the value from there first. If that value is null or there is not a field named "First Name" in your sending DE, it will be pulled from All Subscribers.

In your case and in the code below, if no "First Name" field exists (or if the value is null) in the sending DE and it is null in All Subscribers, "Dear Patient" will be used.

set @fname = trim(attributevalue('first name'))
%%=iif(empty(@fname),"Dear Patient",ProperCase(@fname))=%%,

I also added ProperCase() to ensure the names are capitalized correctly.

  • Jake! This got me really close, thank you so much for looking into this. Including the Capitalized letters was amazing. I just need to add the Dear in front the first name too. I tried putting it in front of the trim, but then I only get the dear. Secondly is pulling from the Profile Attribute if nothing is in the DE part of a marketing cloud feature or is that in the code. Very useful information. – Cameron Feb 13 at 17:18
  • I figured it out! I just put the Dear in front of the code DUH! Thanks to @Gortonington for the reference on that! – Cameron Feb 13 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.