简体   繁体   English

SQL:其中[columnName] = CASE WHEN(条件)然后则为NULL ELSE [columnName]结束

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

Want to run a query in Sybase to do the following: 要在Sybase中运行查询以执行以下操作:

When condition is true, only select records where columnName is null, otherwise, anything else. 当condition为true时,仅选择columnName为null的记录,否则选择其他任何记录。 However, we know that to compare NULL, " = NULL" is not right, we should use "IS NULL" instead. 但是,我们知道比较NULL,“ = NULL”是不正确的,我们应该改用“ IS NULL”。

How can I integrate "IS NULL" to the query then? 然后如何将“ IS NULL”集成到查询中?

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

You could try this alternative query that doesn't use CASE: 您可以尝试不使用CASE的替代查询:

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

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

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