The CASE
is just a "switch" to return a value - not to execute a whole code block.
You need to change your code to something like this:
SELECT
@selectoneCount = CASE @Temp
WHEN 1 THEN @selectoneCount + 1
WHEN 2 THEN @selectoneCount + 1
END
If @temp
is set to none of those values (1 or 2), then you'll get back a NULL