If you are indeed just adding 1 to counting_column
for each condition that is met, you can use a chain of n CASE
statements and add the results together. Each individual CASE
supplies a 0
or 1
, all of which are added together and added to the current value of counting_column
.
UPDATE [table] SET [counting_column] =
(
[counting_column] +
(CASE when [column1] IS NULL then 1 ELSE 0 END) +
(CASE when [column2] IS NULL then 1 ELSE 0 END) +
...
...
(CASE when [column30] IS NULL then 1 ELSE 0 END) +
(CASE when [column31] IS NULL then 1 ELSE 0 END)
)
Note that I have changed the = NULL
to IS NULL
. NULL
is a special non-value that cannot be compared with an equality =
.
I'll also point out that although []
enclosed identifiers are ok in SQLite, this is mostly for compatibility with T-SQL. The more standard approach is to use double-quotes as in UPDATE "table" SET "counting_column" = ...