Replace value in column based on condition

What is the most efficient way to replace a value in a specified column based on a condition from another column?

Example: Replace value A with 20 where value B is 2

  | A  | B
1 | 10 | 1
2 | 30 | 2
3 | 10 | 2

Result:

  | A  | B
1 | 10 | 1
2 | 20 | 2
3 | 20 | 2

Thanks!

Hi Tanja,

a simple CASE WHEN should do what you want:

SELECT 
    CASE WHEN i.B == "2" THEN "20"
         ELSE i.A END AS A,
    i.B
FROM inputTable i

In the Extended Math Processor it’s even shorter

CASE WHEN B == "2"
  THEN "20" ELSE A 
END
1 Like