How to update multiple rows of multiple columns with single value having same condition for every column

Azeem112

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.

Azeem112

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.

edited at
0

Comments

0 comments
Login to comment

Related

Merge rows having same values in multiple columns

how to update multiple column with condition in a single sql query

Update multiple columns based on a single condition in kdb

How to update multiple rows using a single value in laravel?

Condition check, single/multiple value for multiple columns with comma separated column

List a range of multiple columns and rows into a single column

Update 1 column with the unique value of that column from multiple subsets of rows sharing the same value for another column

Update multiple rows using single value

MS SQL How to Update multiple rows with single value?

turning multiple columns/rows into a single column/multiple rows

How to concatenate multiple columns having n no of rows

How to update the same column for multiple rows in DB2

Multiple Rows and Columns to Single Column Excel

In SqlServer, how to join a single column from multiple rows into a single row with multiple columns

Extracting the first row of every column having multiple base rows

How to get multiple column's rows value in a single column?

Grouping rows with same column value on multiple columns

How to compare a value of a single column over multiple columns in the same row using pandas?

how to update multiple rows in a single column to use a different time

Pandas Python groupby multiple columns - sort rows by values in column 2 based on column one having a specific value

How to select rows comparing multiple columns with the same value?

How to convert multiple column values to a single column having multiple rows in Postgres

Replace existing column with same condition for multiple columns

How to update multiple columns having the same value or different values in SQL?

Highcharts: when having multiple columns for the same X axis value, how can I get 1 tooltip per column?

How to update multiple columns in window frame based on other column value on same window frame

How to concatenate multiple rows list with same value into single row

R - How to reshape multiple rows into single row with same column structure

How to get a single row where multiple rows share the same column value