I am using SQL Server to create my database.
I want to add a column to my table that will calculate the number of NULL values ββin each row, for example:
Column1 | Column2 | Column3 | Score a | B | C | 0 x | NULL | NULL | 2
I currently have the following:
Column1 | Column2 | Column3 a | B | C x | NULL | NULL
I created a new column called Score, and to calculate it, I used:
SELECT CASE WHEN Column1 IS NULL THEN 1 ELSE 0 END + CASE WHEN Column2 IS NULL THEN 1 ELSE 0 END + CASE WHEN Column3 IS NULL THEN 1 ELSE 0 END As TMP FROM MyTable
This returns a column with all my rows and a metric for each row:
|TMP 1 |0 2 |2
I would like to update the Score column in myTable with these values.
Thank you for your help.
source share