Reputation: 47
I'm trying to modify one of my queries to select all values in the db, but also replace all values that are either NULL or "-" in the column "RA" with the value "No RA".
Select *,
IF(RA IS NULL OR RA='-', 'No RA', RA)
from dbname
When I do the above command, it's replacing the values but it replaces them in a newly created column called "IF(RA IS NULL OR RA='-', 'No RA', RA)". How can I do by only modifying the existing RA column?
Thank you for your time.
Upvotes: 1
Views: 1112
Reputation: 133360
just don't use select * but use a proper select using explicit column name for all the columns you need
Select IF(RA IS NULL OR RA='-', 'No RA', RA) RA, col2, col3
from dbname
Upvotes: 1
Reputation: 222402
You need to enumerate the columns that you want to select
, and alias the compted expression:
select
co11,
col2,
..., -- other columns to return (excepted "ra")
case when ra is null or ra = '-' then 'No RA' else ra end ra
from dbname
Upvotes: 1