0

In my Data Extension there is a field, Age, with a value of 100.

I want to change this value from 100 to something completely different like Red or One-Hundred.

Can this be done with AMPscript?

Note: the Field has the number Data Type.

Update:

My current solution is replacing my Age field, however the code after the ELSEIF is not being executed. I'm not sure why.

%%[ 
    
    var @Age 
    
    IF @Age > "99" THEN 
    set @termsYear = "Whole of life" 
    UpdateDE("TestDE",1,"Age", @Age, "Age", @termsYear) 
    ELSEIF @Age < "99" THEN 
    set @termsYear = AttributeValue("Age") 
    ENDIF 

]%%

2 Answers 2

1

If it’s a number, then you can only change it to another number, and you can do it using the Update functions I mention below.

If you need a text field, the I suggest you add a brand new column to your DE with a text field type.

Then, use the Update function to change/add new values:

UpdateDE (used in email):

This function updates the Data Extension row referenced in the column and value arguments. Values updated are specified with column name and value pairs. This function does not return a value.

UpdateData (used on a CloudPage):

This function updates the Data Extension row referenced in the column and value arguments. Values updated are specified with column name and value pairs. It returns the number of rows updated by the operation.

3
  • UpdateDE is working for the most part. I have updated my question with some additional code. Any help would be greatly appreciated! Commented Feb 6, 2023 at 13:35
  • Two comments on the script you added: you should identify a row to update by it’s primary key, not by age, and like mentioned above, you cannot update a numeric field with text
    – zuzannamj
    Commented Feb 6, 2023 at 14:34
  • Apologies I missed the part, identifying a new row. Thank you for your answer, Zuzanna. Commented Feb 6, 2023 at 15:23
2

You cannot update the value in a number type field by a text value, like @zuzannamj suggested above, you should create a new column field with the text field type.

For example: If I have the new text field type call "Age in text", I would try like something like this:

%%[ 
    var @Age
    set @Age = AttributeValue("Age") 
    set @Age = 100 /* test */
    
    IF @Age >= 99 THEN 
    set @termsYear = "Whole of life" 
    UpdateDE("TestDE",1,"Age", @Age, "Age in text", @termsYear)
    ELSEIF @Age < 99 THEN 
    set @termsYear = @Age
    ENDIF 

]%%
Output: %%=v(@termsYear)=%%
1
  • Right ok, all makes sense now. I need to create a new column. Thanks Commented Feb 6, 2023 at 15:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .