So the state data in our database is abbreviation but we have a client who wants to display the state dynamically in the body of the email but they want to display the full state name. I'm fairly new to Ampscript and I was able to get this code below to work correctly:

Here's the ampscript code

Var @StateName

IF @state == 'CA' THEN
  Set @StateName = 'California'

And this is what I add to the body of the email: %%=v(@StateName)=%%

Could I use this same code for all 50 states, yes. However, I wanted to know if there some easier Ampscript function that I just don't know about to convert state abbreviations to full names.


The easiest way is to get a data extension that contains the 2 letter abbreviation as the key and the full name in a second field.


  Abbreviation       FullState
      NJ             New Jersey
      CA             California

From here you can just do a lookup from your email, rather than have bulky AMPScript in each email.

For example:

    SET @State = AttributeValue("State")

    SET @FullState = Lookup("yourStateDE", "FullState", "Abbreviation", @State)



Output (using NJ as State)

`New Jersey`

This is much more easily repeatable if needed in any future emails or Landing pages, etc. Plus it leaves easy maintenance, so you can make the change in a single location, instead of inside every email containing that script.


As per showing US states from their abbreviations - the only easier way I can see is by setting the IF and ELSE statements.

Source of abbreviations here.

However I have done the IF and ELSE logic by using the nested IIF statements which is essentially the same thing but reduces the effort of writing the reptitive ELSE.

Note: If the abbreviations do not match with any of the comparisons then it will set the defualt value to the @variable from your DE. Also feel free to add and remove the logic and please make sure you match the closing brackets.

Here is the code:

VAR @state, @StateName

SET @state = Uppercase('State field in DE')

SET @StateName = 
IIF((@state=='AL'), 'Alabama',
IIF((@state=='AK'), 'Alaska',
IIF((@state=='AZ'), 'Arizona',
IIF((@state=='AR'), 'Arkansas',
IIF((@state=='CA'), 'California',
IIF((@state=='CO'), 'Colorado',
IIF((@state=='CT'), 'Connecticut',
IIF((@state=='DE'), 'Delaware',
IIF((@state=='DC'), 'District of Columbia',
IIF((@state=='FL'), 'Florida',
IIF((@state=='GA'), 'Georgia',
IIF((@state=='HI'), 'Hawaii',
IIF((@state=='ID'), 'Idaho',
IIF((@state=='IL'), 'Illinois',
IIF((@state=='IN'), 'Indiana',
IIF((@state=='IA'), 'Iowa',
IIF((@state=='KS'), 'Kansas',
IIF((@state=='KY'), 'Kentucky',
IIF((@state=='LA'), 'Louisiana',
IIF((@state=='ME'), 'Maine',
IIF((@state=='MT'), 'Montana',
IIF((@state=='NE'), 'Nebraska',
IIF((@state=='NV'), 'Nevada',
IIF((@state=='NH'), 'New Hampshire',
IIF((@state=='NJ'), 'New Jersey',
IIF((@state=='NM'), 'New Mexico',
IIF((@state=='NY'), 'New York',
IIF((@state=='NC'), 'North Carolina',
IIF((@state=='ND'), 'North Dakota',
IIF((@state=='OH'), 'Ohio',
IIF((@state=='OK'), 'Oklahoma',
IIF((@state=='OR'), 'Oregon',
IIF((@state=='MD'), 'Maryland',
IIF((@state=='MA'), 'Massachusetts',
IIF((@state=='MI'), 'Michigan',
IIF((@state=='MN'), 'Minnesota',
IIF((@state=='MS'), 'Mississippi',
IIF((@state=='MO'), 'Missouri',
IIF((@state=='PA'), 'Pennsylvania',
IIF((@state=='RI'), 'Rhode Island',
IIF((@state=='SC'), 'South Carolina',
IIF((@state=='SD'), 'South Dakota',
IIF((@state=='TN'), 'Tennessee',
IIF((@state=='TX'), 'Texas',
IIF((@state=='UT'), 'Utah',
IIF((@state=='VT'), 'Vermont',
IIF((@state=='VA'), 'Virginia',
IIF((@state=='WA'), 'Washington',
IIF((@state=='WV'), 'West Virginia',
IIF((@state=='WI'), 'Wisconsin',
IIF((@state=='WY'), 'Wyomingr', @state

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.