I have a table that contains 4 columns and in the 5th column I want to store the count of how many non-null columns there are out of the previous 4. For example:
SELECT Column1,
Column2,
Column3,
Column4,
CASE WHEN Column1 IS NOT NULL THEN 1 ELSE 0 END +
CASE WHEN Column2 IS NOT NULL THEN 1 ELSE 0 END +
CASE WHEN Column3 IS NOT NULL THEN 1 ELSE 0 END +
CASE WHEN Column4 IS NOT NULL THEN 1 ELSE 0 END AS Column5
FROM Table