TopAnswers Databases
I have a question about this fiddle:


Is it ever possible to get -1 as the result of this query? 
I think no, right because potato can be either null or not null and the case covers both scenario? 

sql server 11 

Top Answer
CC BY-SA 4.0Ami
You are correct.

The CASE conditional expression can evaluate to either 1 or 0, never to a NULL.

The encapsulating ISNULL function will always see a concrete value, `1` or `0`, and so will never return `-1`.

If you explain what you are trying to achieve with this code that doesn't seem to work for you, we may be able to offer some advice.
@Ami I edited the answer. The isnull can return 1 or 0, whatever the case returns. It is true that it can never return -1.
Lamak replying to Anonymous
that fiddle seems to work fine?
the real code is not much more complex than this. just trying to understand if I am missing something... 
have you tried `set @potato = null;` and seeing what is returned?  Also, try removing the `set` statement altogether.  This seems like a pretty easy thing to prove.  If you have a more complex scenario in reality, please post that.  Cheers!