InsertData()

Inserts rows into a data extension, and returns the number of rows inserted.

Use this function in CloudPages, landing pages, microsites, and SMS messages in Mobile Connect. Use the InsertDE() function to insert rows into a data extension from emails.

Availability

<table> <tr> <td>Marketing Cloud Engagement</td> <td>✅ Yes</td> </tr> <tr> <td>Marketing Cloud Next</td> <td>❌ No</td> </tr> </table>

Syntax

InsertData(dataExt,
           columnName1, valueToInsert1,
           [columnName2, valueToInsert2 ...])

The InsertData() function has three parameters:

  • dataExt (string): Required. The name of the data extension that you want to insert data into.
  • columnName1 (string): Required. The name of the column to insert into the data extension.
  • valueToInsert1 (string): Required. The value to insert into the specified column.

You can insert multiple values into a row by appending column names and field values to the end of the function.

Usage

To use the function, first pass it the name of the data extension that you want to insert data into. Next, pass it the name of the column to insert data into. Finally, pass the data that you want to insert into the specified column.

Imagine you have a Flights data extension that contains the data in this table.

FlightId Origin Dest Price PerBagSurcharge
1 IND NYC 100
2 IND LAX 200
3 IND SEA 500 25

To insert a new row, use this function.

%%[
  Var @newFlight
  Set @newFlight = InsertData("Flights", "FlightId", 4, "Origin", "IND", "Dest", "ORD", "Price", "125", "PerBagSurcharge", null)
  Output(v(@newFlight))
]%%

The function inserts the specified row. The data extension now contains this data.

FlightId Origin Dest Price PerBagSurcharge
1 IND NYC 100
2 IND LAX 200
3 IND SEA 500 25
4 IND ORD 125

The function returns 1, indicating that it inserted one row.

See Also