sql - 如何在不相互依赖的where子句中添加多个参数
问题描述
我需要一个带有 5 个参数的查询,例如...
姓名,姓氏,出生地,出生日期,ID。
该参数应默认为 null 并且不相互依赖。运行报告时,我应该仅使用 ID 等进行过滤。有时我可以使用 2 个或更多参数进行过滤
解决方案
SQL将沿着
Select
your columns
from some_table
where
(@name = some_table.name_column or @name is null)
and
(@surname = some_table.surname_column or @surname is null)
and
(@birth_place = some_table.birth_place_column or @birth_place is null)
and
(@dateofbirth= some_table.dateofbirth_column or @dateofbirth is null)
and
(@ID= some_table.ID_column or @ID is null)
现在在 SSRS 中,允许您的所有参数为空值。当然.. 您需要选择至少一个参数值,否则您实际上是从表中返回所有内容.. 我敢肯定这是您不想要的。
推荐阅读
- sqlalchemy - FastAPI - 在 index.html 中呈现模板 - 不工作
- python - Python 全局变量混淆
- azure - SQL 托管实例迁移验证
- php - 为什么 WooCommerce 订单简码会在自定义感谢页面上生成插件通知?
- node.js - 我应该在 Node.js 中同时使用 MongoDB 和 Mongoose 吗?
- c++ - 如何重载对象 = 常量 int + 对象
- java - groovy 中如何使用线程迭代 40 万条记录
- azure - 我们能否为 Azure Dev Ops 自定义模板中的自定义字段暗示正则表达式
- git - 如何使用 Visual Studio 将 GIT 分支更改还原为以前的提交
- autodesk-forge - 启用伪造查看器测量的条件是什么?