I'm trying to write a bit of AMPscript that does the following:

IF firstname exists say "John, your"

IF no firstname say "Your"

I tried this, but it doesn't work:

%%=iif(empty(@firstName),"Your", concat(propercase(@firstName, "your")))=%%

I know it's a simple answer, help would be greatly appreciated!


You have a couple issues with it, but were 90% of the way there. (Assuming you have @firstName correctly defined above this snippet of course)

%%=iif(empty(@firstName),"Your", concat(propercase(@firstName, "your")))=%%
should be:
%%=iif(empty(@firstName),"Your", concat(propercase(@firstName), ", your"))=%%

The difference being: 1. altering the propercase to only go around @firstName so that the 'your' does not become capitalized as well. 2. Adding a comma and a space (', ') to your concat string value so it shows John, your instead of Johnyour

That is pretty much it! Like I said, you were 90% of the way there! Great Job.

I saw your comment on another answer asking about setting FirstName if that does not exist in the Sendable data. See below for best practice to handle this:

SET @firstName = AttributeValue("firstName")
Utilizing AttributeValue will allow a null value for @firstName if the field does not exist, instead of causing an error like the raw personalization string would (SET @firstName = firstName)

Final block would be:

VAR @firstName
SET @firstName = AttributeValue("firstName")

%%=iif(empty(@firstName),"Your", concat(propercase(@firstName), ", your"))=%%

Assuming firstName field in the sending DE is John, the output would be:
John, your
and if firstName is empty or field does not exist, output would be:

  • Thank you for your reply. I do already have Attribute Value in there however. I have this: %%[var /*@firstName*/ set /*@firstName*/ = AttributeValue("firstName")]%% With your previously supplied AMPscript as the actual dynamic copy. Have I implemented it incorrectly somewhere? – Thomas Hockey Nov 18 '19 at 13:07
  • ...you'll see that I failed to effectively comment out the AMPscipt - but you get the idea! – Thomas Hockey Nov 18 '19 at 13:08
  • Correct. I am going to edit my answer to show it fully implemented. – Gortonington Nov 18 '19 at 14:37
  • 1
    Great, thank you. That worked. – Thomas Hockey Nov 18 '19 at 16:33

Try this:


set @firstName = AttributeValue("firstName")
set @your = Iif(not Empty(@firstName), Concat(ProperCase(@firstName), ", your"), "Your")





If the field does not exist in the sendable Data Extension, it will render as the fallback version, in this case “Your”.


I'll assume you've SET @FirstName correctly.

I would try it a little differently...maybe not as slick but:

%%[ IF @FirstName is null THEN ]%% Your %%[ELSE]%% %%=ProperCase(@FirstName)=%%, your %%[ENDIF]%%


%%[ IF Empty(AttributeValue("FirstName")) THEN ]%% Your %%[ELSE]%% %%=ProperCase(@FirstName)=%%, your %%[ENDIF]%%

  • Thank you, this worked. However, I've also come across another scenario. What if there is no Firstname column at all in the Data Extension, how would I account for that as well? – Thomas Hockey Nov 15 '19 at 20:38
  • 1
    @ThomasHockey - I edited my answer to provide information on how to handle your comment above. – Gortonington Nov 15 '19 at 21:33

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.