Home > Net >  When column entry is "other' then replace with entry from another column
When column entry is "other' then replace with entry from another column

Time:04-11

I hope someone can help (this is my first time posting!). Basically I want to do the following: when the entry in column a is 'other' replace with the entry in column b

I have tried numerous things with no success. This was most recent attempt:

select column_a, column_b from [data_table] update set column_a = column_b where column_a = 'other'

Any ideas?

CodePudding user response:

This should work,

And please include the errors, or issues in more detail.

select column_a, column_b from data_table
update data_table
set column_a = column_b
where column_a = 'other' ;

CodePudding user response:

It depends on whether you want to change the data in the database, or you just want the report to reflect the data you want.

Just for SELECT into a report:

SELECT 
  column_a
, CASE column_a
    WHEN 'other' THEN column_b
    ELSE column_a
  END AS column_a
, column_b
FROM data_table
;

To change the data in the database:

UPDATE data_table
SET column_a = column_b
WHERE column_a = 'other'

  • Related