sql-server - MSSQL: Date is greater than specific date or is null
问题描述
This is so basic, i'm already sorry.
Where clause is: start date greater than 7/1/18 and end date is greater than 10/1/18 or is null
This where clause gets me what I need, but I'd rather use 'ISNULL' instead of OR.
WHERE l.[Start Date] > '07/01/2018' and (l.[End Date] > '10/1/2018' or l.[End Date] is null)
Can I say:
WHERE l.[Start Date] > '07/01/2018' and (l.[End Date] > ISNULL(l.[End Date]) or something?
解决方案
如果你愿意isnull()
,你可以这样做:
WHERE l.[Start Date] > '07/01/2018' and isnull(l.[End Date], '11/1/2018') > '10/1/2018'
如果l.[End Date]
是null
那么
isnull(l.[End Date], '11/1/2018')
将返回
'11/1/2018'
和条件
isnull(l.[End Date], '11/1/2018') > '10/1/2018'
将返回true
。
当然,您可以使用任何日期,例如'1/1/2099'
推荐阅读
- rust - `const fn` 中不允许带有 match` 的货物编译错误
- azure-java-tools - 运行 azure-webapp-maven-plugin 配置的 SSL 问题
- sdl - 访问 Emscripten 实例上的 SDL 属性
- php - Laravel:使用空值更新输入
- python - 列表理解:每个循环的多维项
- java - 为 UserCredentials 和 UserPermissions 设计带有嵌入式类的 Spring-Security UserDetails 类
- html - 你们能帮帮我吗?为什么引导卡留在移动视图中
- pycharm - PyCharm - 如何更改鼠标颜色
- java - 在 opentok Android 中截取订阅者的屏幕截图
- git - 从 git diff 日志中删除索引