检查两个日期之间的日期或sql中的NULL [英] check date between two dates or NULL in sql

查看:229
本文介绍了检查两个日期之间的日期或sql中的NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在between two dates中进入check date或可以作为NULL通过 使用存储的过程

I want to check date in between two dates or can pass as a NULL using stored proc

代码

declare @fromDate date = null
declare @toDate date = null

select * from Mytable 
where date betweeen @fromDate and @toDate OR NULL (how to check for both parameters)

我还有其他2个参数,因此无论日期结果如何都应显示. 如果@todate和@fromDate为NULL

I have other 2 more parameters so irrespective with date result should be displayed. if @todate and @fromDate is NULL

请帮助.

推荐答案

尝试以下合并功能

declare @fromDate date = null
declare @toDate date = null

select * from Mytable 
where date between coalesce(@fromDate,date) and coalesce(@toDate,date)

这篇关于检查两个日期之间的日期或sql中的NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆