InsertData
This function inserts a row in a Data Extension with the specified column name and value pairs. It returns the number of rows inserted by the operation.
Arguments
InsertData(1,2,3,[4a,4b]...)
Ordinal | Type | Required | Description |
---|---|---|---|
1 | String | True | Name of the Data Extension receiving the new row |
2 | String | True | Name of the column receiving the value |
3 | String | True | Value to insert into the column |
4a | String | False | Additional column name receiving the value (see note) |
4b | String | False | Additional value to insert into the column (see note) |
NOTE: Additional pairs of columns and values can be appended as arguments.
NOTE: This function only works in a landing page, microsite page or CloudPage, or in an SMS message in MobileConnect. Use the InsertDE function if you need to insert rows into a Data Extension in an email.
Example 1
The following illustrates the use of this function with the minimum number of arguments.
Data Extension: LoyaltyMembers
Name | Data Type | Length | Primary Key | Nullable | Default Value |
---|---|---|---|---|---|
EmailAddress | EmailAddress | 254 | N | N | |
SubscriberKey | Text | 254 | Y | N | |
FirstName | Text | 50 | N | Y | |
LastName | Text | 50 | N | Y | |
Created | Date | N | Y | Current Date |
The LoyaltyMembers Data Extension includes these rows:
EmailAddress | SubscriberKey | FirstName | LastName | Created |
---|---|---|---|---|
doug@limedash.com | 8473 | Doug | Smith | 2017-10-21 12:01 |
suzy@limedash.com | 5497 | Suzy | Jackson | 2017-10-20 11:01 |
dale@limedash.com | 7114 | Dale | Cameron | 2017-10-19 10:01 |
Here is an example utilizing the preceding context:
%%[
var @insertCount, @emailAddress, @subscriberKey
set @emailAddress = "barb@limedash.com"
set @subscriberKey = "5767"
set @insertCount = insertData("LoyaltyMembers","EmailAddress", @emailAddress,"SubscriberKey", @subscriberKey)
]%%
insertCount: %%=v(@insertCount)=%%
Output
insertCount: 1
After the operation, the LoyaltyMembers Data Extension includes these rows:
EmailAddress | SubscriberKey | FirstName | LastName | Created |
---|---|---|---|---|
doug@limedash.com | 8473 | Doug | Smith | 2017-10-21 12:01 |
suzy@limedash.com | 5497 | Suzy | Jackson | 2017-10-20 11:01 |
dale@limedash.com | 7114 | Dale | Cameron | 2017-10-19 10:01 |
barb@limedash.com | 5767 | 2017-10-22 13:01 |
Example 2
Not a subscriber? Subscribe now.