开发者

Visual Studio 2008 Case Expression using null

I'm trying to right a report that lets a user select either 'all values including null' or 'all values excluding null'. I placed a case expression in the where section. It doesn't work correctly for two reasons:

  • I can't 开发者_开发问答pull the values of null and is not null at the same time.
  • In both cases it ends up pulling all values including null for the first one and only null values for the second.

Where

((CASE WHEN @nullvalue = 1 THEN check_rtn_void_dte end is not null) OR (CASE WHEN @nullvalue = 2 THEN check_rtn_void_dte end is null))

Is there a operator I can use that will pull null and is not null in one statement? Also, why is the first case pulling all data including null values?


Perhaps something like this would be simpler...

SELECT *
FROM MyTable
WHERE (@nullvalue = 2 OR check_rtn_void_dte IS NOT NULL)

That should pull out all results if @nullvalue = 2, or only non-NULL values if @nullvalue is something else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜