Get Started with AMPscript Development—Lesson 1
Get Started with AMPscript Development—Lesson 2
Get Started with AMPscript Development—Lesson 3
Get Started with AMPscript Development—Lesson 4
Data Structures
Impression Tracking
Enterprise Awareness
This lesson introduces you to the basics of using AMPscript in your messages.
Northern Trail Outfitters (NTO), the fictitious company that we refer to in this lesson, has a sendable data extension that contains several pieces of information about their subscribers.
| Data Extension Column Name | Description |
|---|---|
MemberID | A unique member ID number for the subscriber |
FirstName | The subscriber’s first or given name |
LastName | The subscriber’s surname or family name |
PrefName | The subscriber’s preferred name |
Address | The subscriber’s street address |
City | The city that the subscriber lives in |
State | The state, province, or other subnational unit where the subscriber lives |
PostalCode | The subscriber’s postal code |
MemPref | The subscriber’s preferred outdoor activity |
Plat | A true or false value that indicates whether the subscriber is a platinum rewards member |
This code example contains the message content for this lesson.
1%%[
2 Var @memid, @fname, @lname, @prefname, @address, @zip, @mempref, @plat
3 Set @memid = MemberID
4 Set @fname = FirstName
5 Set @lname = LastName
6 Set @prefname = PrefName
7 Set @address = Address
8 Set @postcode = PostalCode
9 Set @mempref = MemPref
10 Set @plat = Plat
11]%%
12
13Hello %%= v(@fname) =%%! Here are your account details.
14First Name: %%= v(@fname) =%%
15Last Name:%%= v(@lname) =%%
16Preferred Name: %%= v(@prefname) =%%
17Address Address: %%= v(@address) =%%
18Postal Code: %%= v(@zip) =%%
19Member Preferences Shopping Preference: %%= v(@mempref) =%%
20Platinum Member: %%= v(@plat) =%%If you’re new to AMPscript, it’s helpful to move through the AMPscript sample code line by line so that you can better understand how AMPscript works.
The example begins with %%[, which indicates the beginning of a block of AMPscript code.
The second line of the example begins with Var, followed by several names that begin with @. Each of these names is used as a variable later in the code example. The @ sign is required at the beginning of each AMPscript variable. At this point, all of the variables have been declared, but the value for each one is null.
1Var @memid, @fname, @lname, @prefname, @address, @zip, @mempref, @platThe next several lines begin with Set, followed by the name of one of the declared variables. These lines assign a value to each of the declared variables. The value of each variable is set to equal the corresponding column in the sendable data extension that this email targets. When the email is sent, the system retrieves the value in the specified column for each subscriber and assigns that value to the variable.
1Set @memid = MemberID
2 Set @fname = FirstName
3 Set @lname = LastName
4 Set @prefname = PrefName
5 Set @address = Address
6 Set @postcode = PostalCode
7 Set @mempref = MemPref
8 Set @plat = PlatAfter the variable assignments is the string ]%%. This string indicates the end of a block of AMPscript code.
After the initial AMPscript block is closed, we see the first line of the message body. This line is the first that produces content that’s visible to the subscriber.
This line contains the text %%= v(@fname) =%%. The %%= indicates the beginning of a string of inline AMPscript code, and the =%% indicates the end. Between these tags is the function v(@fname). The v() function is a utility function that outputs the value of a variable. The function refers to the @fname variable.
1Hello %%= v(@fname) =%%! Here are your account details.When a subscriber receives an email that contains this code, their name appears in the text instead of the AMPscript code.
If you’re new to Marketing Cloud Engagement, see Get Started with Email Studio to learn more about creating an email.
This lesson assumes that you’re familiar with creating an email and that you already set up Marketing Cloud Engagement to send emails.


