I recently began teaching myself (terrible) SQLite. One thing that struck me as annoying was the CASE expression, namely the fact that it employs short-circuit evaluation.
Is there any way to get around this? I am looking for a CASE statement that does not employ short-circuit evaluation.
UPDATE [table]SET [counting_column] =
(
CASE
when [column1] = NULL
then [counting_column] + 1
...
when [column31] = NULL
then [counting_column] + 1
end
)
I would like each entry in the database to be tested by each case statement, not just the first one that evaluates to true. Any help would be much appreciated.
NOTE: I apologize if there’s some glaring error– I’m quite new at this so go easy please.
If you are indeed just adding 1 to
counting_columnfor each condition that is met, you can use a chain of nCASEstatements and add the results together. Each individualCASEsupplies a0or1, all of which are added together and added to the current value ofcounting_column.Note that I have changed the
= NULLtoIS NULL.NULLis 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 inUPDATE "table" SET "counting_column" = ...