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. To update rows in a data extension in an email, use the UpdateDE() function.
The UpdateData()
function has six parameters:
dataExt
(string): Required. The name of the data extension that contains the data to update.columnValuePairs
(number): Required. The number of column and value pairs for the function to match against.searchColumnName1
(string): Required. The name of a column to search for the data to update.searchValue1
(string): Required. The value that the function uses to determine which row to update. You can specify multiple column and value pairs to match against.columnToUpdate1
(string): Required. The column that contains the data to update.updatedValue1
(string): Required. The data to update in the specified column. You can specify multiple column and value pairs to update.
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.
FlightId | Origin | Dest | Price | PerBagSurcharge |
---|---|---|---|---|
1 | IND | NYC | 100 | |
2 | IND | LAX | 200 | |
3 | IND | SEA | 500 | 25 |
4 | ORD | SEA | 525 | 10 |
5 | ORD | LAX | 400 | |
6 | SEA | SAN | 300 | |
7 | SEA | ATL | 10 | |
8 | ATL | AUS | 350 | 10 |
9 | STL | KCA | 5 | |
10 | IND | ATL | 125 |
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.
FlightId | Origin | Dest | Price | PerBagSurcharge |
---|---|---|---|---|
1 | IND | NYC | 100 | |
2 | IND | LAX | 200 | |
3 | IND | SEA | 500 | 25 |
4 | ORD | SEA | 525 | 10 |
5 | ORD | LAX | 400 | |
6 | SEA | SAN | 300 | |
7 | SEA | ATL | 10 | |
8 | ATL | AUS | 350 | 10 |
9 | STL | KCA | 5 | |
10 | IND | ATL | 225 |
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.
FlightId | Origin | Dest | Price | PerBagSurcharge |
---|---|---|---|---|
1 | IND | NYC | 100 | |
2 | IND | LAX | 200 | |
3 | IND | SEA | 500 | 25 |
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.
FlightId | Origin | Dest | Price | PerBagSurcharge |
---|---|---|---|---|
1 | IND | JFK | 75 | 10 |
2 | IND | LAX | 200 | |
3 | IND | SEA | 500 | 25 |
If you receive errors or notice incomplete updates when you use this function, consider these factors:
- If you specify a value for the
columnValuePairs
parameter that doesn’t agree with the number of matching criteria in the function, the function returns 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 returns0
. - If you specify a value for the
updatedValue
parameter that’s of a different data type than the column that you specified in thecolumnToUpdate
parameter, the function doesn’t update any data and returns0
. 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
andsearchValue
) doesn’t equal the number of update parameters (columnToUpdate
andupdatedValue
), 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.