I want to update a column based on the occurrences of values in multiple columns.
SQL Server 2017 schema setup:
CREATE TABLE Table1 (Part varchar(10),Jan int,Feb int,Mar int,Apr int,Occurrences int)
INSERT INTO Table1 (Part,Jan,Feb,Mar,Apr,Occurrences)VALUES('AAA',null,2,null,1,null),
('BBB',2,3,5,7,null),
('CCC',3,null,null,null,null),
('DDD',4,7,1,null,null)
I want to update the Occurrences column based on the values existing in Jan,Feb,Mar,Apr columns. It should skip the null occurrences and count only if value exists.
For the above schema the occurrences column should be updated as
How can I achieve this?