简体   繁体   English

使用 null 的 Visual Studio 2008 案例表达式

[英]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'.我正在尝试纠正一个报告,该报告允许用户 select '所有值包括空值'或'所有值不包括空值'。 I placed a case expression in the where section.我在 where 部分放置了一个 case 表达式。 It doesn't work correctly for two reasons:它不能正常工作有两个原因:

  • I can't pull the values of null and is not null at the same time.我不能同时提取 null 和 null 的值。
  • In both cases it ends up pulling all values including null for the first one and only null values for the second.在这两种情况下,它最终都会提取所有值,包括第一个的 null 和第二个的仅 null 值。

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?有没有我可以使用的操作员在一个语句中拉 null 而不是 null? Also, why is the first case pulling all data including null values?另外,为什么第一个案例会提取所有数据,包括 null 值?

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.如果@nullvalue = 2,则应该提取所有结果,或者如果@nullvalue 是其他值,则只提取非空值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM