简体   繁体   中英

SQL: where [columnName] = CASE WHEN (condition) THEN NULL ELSE [columnName] END

Want to run a query in Sybase to do the following:

When condition is true, only select records where columnName is null, otherwise, anything else. However, we know that to compare NULL, " = NULL" is not right, we should use "IS NULL" instead.

How can I integrate "IS NULL" to the query then?

select * from tableName
where columnName = CASE WHEN (condition) THEN NULL ELSE columnName END

You could try this alternative query that doesn't use CASE:

select * from tableName
where ((condition) AND columnName IS NULL) Or (Not (condition))

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