UpdateDE()
Updates data in a data extension. This function doesn’t return any output.
You can use this function to update data in a data extension in an email. Use the UpdateData()
function to update rows in CloudPages, landing pages, microsites, and SMS messages in MobileConnect.
The UpdateDE()
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.
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 UpdateDE()
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 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 returns0
. - If you specify a value for the
updatedValue
parameter that is 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.