I have a table having different type of Fees like security fees, tuition fees, admission fees etc and all of these column accept null values too.
I want to update all null values of these columns with 0 value. I can write different update query for each column but because condition and value for all the columns is same I wanna learn to do it in a single update query.
Table_Fees
securityFees | TuitionFees | AdmissionFees
150 500 null
null 450 120
150 null 120
How can I replace all null values with zero?
Update Table_Fees
set securityFees = 0,
TuitionFees = 0,
AdmissionFees = 0
where securityFees = null
and TuitionFees = null
and AdmissionFees = null;
or/and both operator are not useful in this case
PS: I can't change the structure of table. I can only replace null values with 0 through coding.
I've solved the answer by CASE
Update Table_Fees
set securityFees = CASE when securityFees = null then 0 else securityFees END,
TuitionFees = CASE when TuitionFees = null then 0 else TuitionFees END,
AdmissionFees = CASE when AdmissionFees = null then 0 else AdmissionFees END;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments