salesforce-marketing-cloudampscript

Conditional AMPscript required


I need a simple bit of AMPscript to serve up one type of email salutation where the First Name exists in the database and one where I don't.

So, IF Firstname is null: "Hello," - IF Firstname is not null: "Dear @Firstname"

Embarrassingly, everything I've tried hasn't worked. I'm aware that this is a painfully simple bit of AMPscript


Solution

  • Here's how I'd do it:

    %%[
    
    var @firstName
    set @firstName = AttributeValue("firstName")
    
    ]%%
    
    <!-- some other HTML -->
    
    %%=iif(empty(@firstName),"Hello", concat("Dear ", propercase(@firstName)))=%%,
    

    Reference: