Skip to main content
Inspiring
July 31, 2008
Question

Select in SQL server

  • July 31, 2008
  • 1 reply
  • 399 views
Please someone explain this [ (CST.total_calls) IN (0, NULL) ] in plain English?
This topic has been closed for replies.

1 reply

emmim44Author
Inspiring
July 31, 2008
I think it could be if average is zero or null then the average is 0.... Thanks all
Inspiring
August 1, 2008
emmim44 wrote:
> I think it could be if average is zero or null then the average is 0.... Thanks all

I suspect that is what the author intended. However, the statement might not return correct results. That expression is similar to saying:

WHEN AVG(CST.total_calls) = 0 OR AVG(CST.total_calls) = NULL

NULL is a special value. In most modern databases, null is never equal to anything. Not even itself. To detect null values you use the keywords "is null" instead of the equality operator "=".

WHEN AVG(CST.total_calls) = 0 OR AVG(CST.total_calls) IS NULL

There are also sql functions, like coalesce, that can automatically replace nulls with another value like 0 or an empty string, which can be useful in some cases.