UpdateData()

Updates data in a data extension, and returns the number of rows updated.

You can use this function in CloudPages, landing pages, microsites, and SMS messages in MobileConnect. Use the UpdateDE() function to update rows in a data extension in an email.

The UpdateData() function has six parameters:

  • dataExt (string): Required. The name of the data extension that you want to insert data into.
  • numCols (number): Required. The number of column updates you’re making to the specified row.
  • searchColumnName (string): Required. The name of the column to search for the data you want to update.
  • searchValue (string): Required. The value that the function uses to determine which row to update.
  • columnToUpdate (string): Required. The column that contains the data that you want to update.
  • updatedValue (string): Required. The data to update in the specified column.

You can also use this function to update multiple columns in a single row. See Updating Multiple Values in One Row for more information.

To use the function, first pass it the name of the data extension that contains the data you want to update. Next, pass it the name of the column to search to find the row that you want to update, and the value that identifies the row to update. Finally, pass it the name of the column that you want to update the data in, and the value that you want to update.

In this example, a data extension called "Flights" contains the data in this table.

FlightIdOriginDestPricePerBagSurcharge
1INDNYC100
2INDLAX200
3INDSEA50025
4ORDSEA52510
5ORDLAX400
6SEASAN300
7SEAATL10
8ATLAUS35010
9STLKCA5
10INDATL125

To update the Price value for FlightId 10, use this function.

The function returns 1, indicating that it updated one row. The data extension now contains this data.

FlightIdOriginDestPricePerBagSurcharge
1INDNYC100
2INDLAX200
3INDSEA50025
4ORDSEA52510
5ORDLAX400
6SEASAN300
7SEAATL10
8ATLAUS35010
9STLKCA5
10INDATL225

You can use the UpdateData() function to update more than one column in a single row in one operation. To update multiple columns, you must provide one set of search criteria for each column that you want to update.

This example uses a data extension called "Flights2" that contains the data in this table.

FlightIdOriginDestPricePerBagSurcharge
1INDNYC100
2INDLAX200
3INDSEA50025

Use this code to update the Dest, Price, and PerBagSurcharge fields for FlightId 1.

The function returns 1, indicating that it updated one row. The data extension now contains this data.

FlightIdOriginDestPricePerBagSurcharge
1INDJFK7510
2INDLAX200
3INDSEA50025

If you receive errors or notice incomplete updates when you use this function, consider the following factors:

  • If you specify a value for the numCols parameter that doesn’t agree with the number of updates that you included in the function, the function produces an exception.
  • If you specify a column name for the searchColumnName parameter that doesn’t exist in the specified data extension, the function produces an exception.
  • If you specify a value for the searchValue parameter that isn’t found in the specified column, the function doesn’t update any data and returns 0.
  • If you specify a value for the updatedValue parameter that is of a different data type than the column that you specified in the columnToUpdate parameter, the function doesn’t update any data and returns 0. For example, if you pass a numeric value, but the column contains string data, the function doesn’t update the data.
  • If the number of search parameters (searchColumnName and searchValue) doesn’t equal the number of update parameters (columnToUpdate and updatedValue), the function updates the columns for which you have provided search parameters. For example, if you provide two search parameters and three update parameters, the function only implements the first two update parameters. You can repeat the same update parameters multiple times if necessary.