sql - where 子句中的 case 语句使用 not like and is not null
问题描述
我正在使用存储过程从现有表中提取数据,该存储过程具有用户通过复选框在前端选择的一些是或否选项。我想限制为他们做出的每一个选择写一堆不同的If
陈述。
我的 where 子句的这一部分有效。此列的数据是Y
或N
。
Where... and IsSigned = Case When @IncludeSigned = 'Y' then IsSigned else 'N' end
我想添加到 where usingis not null
以及not like
方括号之间是否可能。到目前为止我有
and SignatureType = case when @IncludeElectronic = 'Y' then Type else [NOT like electronic] end
还
and ReviewDate = Case When @HasReviewDate = 'Y' then [ReviewDate is not null] else null end
解决方案
这可能会帮助您使用 AND/OR 而不是大小写
where (ReviewDate is not null or @HasReviewDate = 'Y' ) And (....)
即当@HasReviewDate = 'Y' 查询将返回ReviewDate 不为null 的记录,当@HasReviewDate != 'Y' 然后查询将返回ReviewDate 为null 的记录
推荐阅读
- vue.js - 在 vuejs 的伊斯坦布尔、摩卡和 vue-test-utils 的覆盖范围内找不到 .vue 文件
- mysql - MYSQL 触发器 - 使用 WHERE 条件更新特定行
- r - 如果满足条件,R 在 DF 上按行应用函数
- linux - 如何使用自定义命令在 PM2 中启动进程
- mongodb - 如何删除不知道其父 ID 的猫鼬数组项?
- r - 如何使函数参数成为R中向量的元素?
- javascript - jQuery UI 滑块 - 设置最大选项更改值
- javascript - Javascript所有字段未得到验证
- python - re.search 总是返回 None
- php - GD 库中的 imagesx() 不能在课堂上使用,但可以单独使用