简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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